Submission #518736

# Submission time Handle Problem Language Result Execution time Memory
518736 2022-01-24T14:07:38 Z ak2006 Poklon (COCI17_poklon) C++14
0 / 140
5000 ms 63680 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void setIO()
{
    fast;
}
const int rn = 700;
map<int,int>freq;
int ans1;
bool cmp(vi&a,vi&b)
{
    if ((a[0]/rn) != (b[0]/rn))
        return ((a[0]/rn) < (b[0]/rn));
    return a[1] < b[1];
}
void add(int i)
{
    if (freq[i] == 1)
        ans1++;
    if (freq[i] == 2)
        ans1--;
    freq[i]++;
}   
void sub(int i)
{
    if (freq[i] == 3)
        ans1++;
    if (freq[i] == 2)
        ans1--;
    freq[i]--;
}
int main()
{
    setIO();
    int n,q;
    cin>>n>>q;
    vi a(n + 1),ans(q);
    vvi queries(q,vi(3));
    for (int i = 1;i<=n;i++)
        cin>>a[i];
    for (int i = 0;i<q;i++){
        int l,r;
        cin>>l>>r;
        queries[i][0] = l,queries[i][1] = r;
        queries[i][2] = i;
    }
    sort(queries.begin(),queries.end(),cmp);
    int curL = 1,curR = 0;
    for (int i = 0;i<q;i++){
        while (curL > queries[i][0]){
            curL--;
            add(a[curL]);
        }
        while (curR < queries[i][1]){
            curR++;
            add(a[curR]);
        }
        while (curL < queries[i][0]){
            sub(curL);
            curL++;
        }
        ans[queries[i][2]] = ans1;
        while (curR > queries[i][1]){
            sub(curR);
            curR--;
        }
    }
    for (int i = 0;i<q;i++)cout<<ans[i]<<"\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 208 KB Output isn't correct
2 Incorrect 6 ms 376 KB Output isn't correct
3 Incorrect 14 ms 320 KB Output isn't correct
4 Incorrect 127 ms 916 KB Output isn't correct
5 Execution timed out 5006 ms 12700 KB Time limit exceeded
6 Execution timed out 5092 ms 12656 KB Time limit exceeded
7 Execution timed out 5045 ms 25496 KB Time limit exceeded
8 Execution timed out 5058 ms 38216 KB Time limit exceeded
9 Execution timed out 5094 ms 50808 KB Time limit exceeded
10 Execution timed out 5098 ms 63680 KB Time limit exceeded