Submission #989626

# Submission time Handle Problem Language Result Execution time Memory
989626 2024-05-28T12:41:10 Z m5588ohammed Poklon (COCI17_poklon) C++14
0 / 140
5000 ms 28244 KB
 #include <bits/stdc++.h>
using namespace std;
#define int long long
int MAXN=200001;
int s=sqrt(MAXN);
 
struct query{
    int l,r,o;
};
int ans;
map <int,int> mp;
bool comp(query a,query b){
    if(a.l/s==b.l/s){
        return a.r<b.r;
    }
    return a.l/s < b.l/s;
} 
void add(int i){
    if(mp[i]==2) ans--;
    else if(mp[i]==1) ans++;
    mp[i]++;
}
void move(int i){
    if(mp[i]==2) ans--;
    else if(mp[i]==3) ans++;
    mp[i]++;    
}
signed main()
{
    int n,q;
    cin>>n>>q;
    int arr[n];
    query Q[q];
    for(int i=0;i<n;i++) cin>>arr[i];
    for(int i=0;i<q;i++){
        int L,R;
        cin>>L>>R;
        Q[i]={L-1,R-1,i};
    }
    sort(Q,Q+q,comp);
    int L=0,R=-1;
    int answer[q];
    for(int i=0;i<q;i++){
        int L1=Q[i].l,R1=Q[i].r;
        while(L<L1){
            move(arr[L]);
            L++;
        }
        while(L>L1){
            L--;
            add(arr[L]);
        }
        while(R<R1){
            R++;
            add(arr[R]);
        }
        while(R>R1){
            move(arr[R]);
            R--;
        }
        answer[Q[i].o]=ans;
    }
    for(int i=0;i<q;i++) cout<<answer[i]<<endl;
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Incorrect 2 ms 348 KB Output isn't correct
3 Incorrect 6 ms 344 KB Output isn't correct
4 Incorrect 28 ms 604 KB Output isn't correct
5 Incorrect 1514 ms 5968 KB Output isn't correct
6 Incorrect 1689 ms 5996 KB Output isn't correct
7 Execution timed out 5074 ms 11348 KB Time limit exceeded
8 Execution timed out 5046 ms 17236 KB Time limit exceeded
9 Execution timed out 5068 ms 22868 KB Time limit exceeded
10 Execution timed out 5068 ms 28244 KB Time limit exceeded