Cod sursa(job #2193013)

Utilizator PredaBossPreda Andrei PredaBoss Data 8 aprilie 2018 13:01:23
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.08 kb
#include <bits/stdc++.h>
#define rest 666013
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
vector<int>h[666015];
vector<int>::iterator low;
int n,c,x;
int main()
{
    fin>>n;
    for(int i=1;i<=n;i++)
    {
        fin>>c>>x;
        if(c==1)
        {
            low=lower_bound(h[x%rest].begin(),h[x%rest].end(),x);
            if(low!=h[x%rest].end() && h[x%rest][low-h[x%rest].begin()]==x)
                continue;
            h[x%rest].push_back(x);
            continue;
        }
        if(c==2)
        {
            low=lower_bound(h[x%rest].begin(),h[x%rest].end(),x);
            if(low==h[x%rest].end() || h[x%rest][low-h[x%rest].begin()]!=x)
                continue;
            h[x%rest].erase(low);
            continue;
        }
        if(c==3)
        {
            bool k=0;
            for(int j=0;j<h[x%rest].size();j++)
                if(h[x%rest][j]==x)
                {
                    k=1;
                    break;
                }
            fout<<k<<"\n";
        }
    }
    return 0;
}