Cod sursa(job #2036804)

Utilizator Alex_AeleneiAlex Aelenei Ioan Alex_Aelenei Data 11 octombrie 2017 09:29:15
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int m=666013;
int h(int key)
{
    return key%m;
}
vector<int>v[m+5];
vector<int>::iterator it;
int main()
{
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    int n,i,op,x,key;
    scanf("%d",&n);
    for(i=1;i<=n;++i)
    {
        scanf("%d%d",&op,&x);
        key=h(x);
        if(op==1)
            v[key].push_back(x);
        else
            if(op==2)
            {
                it=find(v[key].begin(),v[key].end(),x);
                if(it!=v[key].end())
                    v[key].erase(it);
            }
            else
            {
                it=find(v[key].begin(),v[key].end(),x);
                if(it!=v[key].end())
                    printf("1\n");
                else
                    printf("0\n");
            }
    }
    return 0;
}