Submission #401516

# Submission time Handle Problem Language Result Execution time Memory
401516 2021-05-10T12:51:00 Z NintsiChkhaidze Poklon (COCI17_poklon) C++14
28 / 140
167 ms 40588 KB
#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define ll long long
#define int long long
#define left (node<<1),l,((l+r)>>1)
#define right ((node<<1)|1),((l+r)>>1) + 1,r
using namespace std;
const int Bl = 707,N = 500005;
pair<pair<int,int>,int> d[N];
int ans[N],res,a[N];
map <int,int> cnt;
bool cmp(pair<pair<int,int>,int> a,pair<pair<int,int>,int> b){
    if (a.f.f/Bl == b.f.f/Bl) 
        return a.f.s < b.f.s;
    return a.f.f/Bl < b.f.f<Bl;
}
void add(int ind){
    if (cnt[a[ind]] == 2) res--;
    cnt[a[ind]]++;
    if(cnt[a[ind]] == 2) res++;
}
void remove(int ind){
    if (cnt[a[ind]] == 2) res--;
    cnt[a[ind]]--;
    if(cnt[a[ind]] == 2) res++;
}
main (){
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    
    for (int i=1;i<=n;i++)
        cin>>a[i];
    
    for (int i=1;i<=m;i++){
        int l,r;
        cin>>l>>r;
        d[i] = {{l,r},i};
    }
    
    sort(d+1,d+m+1,cmp);
    
    int L = 0,R = -1;
    for (int i=1;i<=m;i++){
        int l = d[i].f.f,r = d[i].f.s,idx = d[i].s;
        while (L > l) add(--L);
        while (R < r) add(++R);
        while (L < l) remove(L++);
        while (R > r) remove(R--);
        ans[idx] = res;
    }
    
    for (int i=1;i<=m;i++)
        cout<<ans[i]<<"\n";
}

Compilation message

poklon.cpp: In function 'bool cmp(std::pair<std::pair<long long int, long long int>, long long int>, std::pair<std::pair<long long int, long long int>, long long int>)':
poklon.cpp:17:28: warning: comparison of constant '707' with boolean expression is always true [-Wbool-compare]
   17 |     return a.f.f/Bl < b.f.f<Bl;
      |            ~~~~~~~~~~~~~~~~^~~
poklon.cpp:17:21: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
   17 |     return a.f.f/Bl < b.f.f<Bl;
      |                     ^
poklon.cpp: At global scope:
poklon.cpp:29:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   29 | main (){
      |       ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 4 ms 332 KB Output is correct
3 Runtime error 112 ms 40128 KB Execution killed with signal 11
4 Runtime error 8 ms 832 KB Execution killed with signal 11
5 Runtime error 35 ms 8232 KB Execution killed with signal 11
6 Runtime error 37 ms 8224 KB Execution killed with signal 11
7 Runtime error 72 ms 16324 KB Execution killed with signal 11
8 Runtime error 100 ms 24468 KB Execution killed with signal 11
9 Runtime error 133 ms 32612 KB Execution killed with signal 11
10 Runtime error 167 ms 40588 KB Execution killed with signal 11