Submission #577595

# Submission time Handle Problem Language Result Execution time Memory
577595 2022-06-15T06:19:22 Z Ronin13 Poklon (COCI17_poklon) C++14
84 / 140
282 ms 35800 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;

struct mo{
    int l, r, ind;
    int bl;
    mo(int l, int r, int ind) : l(l), r (r), ind(ind){
        bl = (l - 1) / 500;
    }
    mo(){
        l = r = ind = 0;
        bl = 0;
    }
};

bool operator < (mo a, mo b){
    return a.bl < b.bl || (a.bl == b.bl && a.r < b.r);
}

vector <mo> qv;

int used[100001];
int a[1000001];
int good;

void add(int ind){
    int x = a[ind];
    if(used[x] == 2) good--;
    used[x]++;
    if(used[x] == 2) good++;
}

void rem(int ind){
    int x = a[ind];
    if(used[x] == 2) good--;
    used[x]--;
    if(used[x] == 2) good++;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    int q; cin >> q;
    int b[n + 1];
    map <int,int> mp;
    for(int i= 1; i <= n; i++){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b + 1, b + 1 + n);
    for(int i = 1; i <= n; i++){
        mp[b[i]] = i;
    }
    for(int i = 1; i <= n; i++){
        a[i] = mp[a[i]];
    }
    int mo_l, mo_r;
    mo_l = 1, mo_r = 0;
    for(int i = 1; i <= q; i++){
        int l, r; cin >> l >> r;
        qv.epb(l, r, i);
    }
    sort(qv.begin(), qv.end());
    vector <int> ans(q + 1);
    for(int i = 0; i < qv.size(); i++){
        int l = qv[i].l, r = qv[i].r, ind = qv[i].ind;
        while(mo_r < r){
            mo_r++;
            add(mo_r);
        }
        while(mo_r > r){
            rem(mo_r);
            mo_r--;
        }
        while(mo_l < l){
            rem(mo_l);
            mo_l++;
        }
        while(mo_l > l){
            mo_l--;
            add(mo_l);
        }
        ans[ind] = good;
    }
    for(int i= 1; i <= q; i++) cout << ans[i] << "\n";
    return 0;
}

Compilation message

poklon.cpp: In function 'int main()':
poklon.cpp:73:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<mo>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |     for(int i = 0; i < qv.size(); i++){
      |                    ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 6 ms 600 KB Output is correct
5 Correct 152 ms 3516 KB Output is correct
6 Correct 168 ms 3584 KB Output is correct
7 Runtime error 93 ms 11644 KB Execution killed with signal 11
8 Runtime error 161 ms 21164 KB Execution killed with signal 11
9 Runtime error 204 ms 28420 KB Execution killed with signal 11
10 Runtime error 282 ms 35800 KB Execution killed with signal 11