Codeforces Round #672 (Div. 2)

摳腳老騷發表於2020-09-25

Codeforces Round #672 (Div. 2)

A. Cubes Sorting

#include <bits/stdc++.h>
//#define int ll
using namespace std;

#pragma GCC optimize(2)

typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 1e5 + 10;

void solve() {
    int n;
    cin>>n;
    int a,flag=1;
    cin>>a;
    for (int i = 1; i < n; ++i) {
        int b;
        cin>>b;
        if (a<=b) flag=0;
        a=b;
    }
    cout<<(flag?"NO":"YES")<<endl;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

B. Rock and Lever

#include <bits/stdc++.h>
//#define int ll
using namespace std;

//#pragma GCC optimize(2)

typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 1e5 + 10;

ll b[50];

void solve() {
    ll n,a;
    cin>>n;
    memset(b,0,sizeof(b));
    for (int i = 0; i <n; ++i) {
        cin>>a;
        int temp=0;
        while (a) temp++,a/=2;
        b[temp]++;
    }
    ll sum=0;
    for (int i = 1; i < 50; ++i) sum+=b[i]*(b[i]-1)/2;
    cout<<sum<<"\n";
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

C1. Pokémon Army (easy version)

#include <bits/stdc++.h>
//#define int ll
using namespace std;

//#pragma GCC optimize(2)

typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 3e5 + 10;

int a[maxn],b[maxn];

void solve() {
    int n,q;
    ll sum=0;
    cin>>n>>q;
    for (int i = 1; i <= n; ++i) cin>>a[i];
    a[n+1]=0;
    for (int i = 1; i <=n; ++i) {
        b[i]=a[i]-a[i-1];
        if (b[i]>0) sum+=b[i];
    }
    cout<<sum<<"\n";
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

相關文章