Cod sursa(job #2036819)

Utilizator MarutBrabete Marius Stelian Marut Data 11 octombrie 2017 09:37:20
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.15 kb
//#include<bits/stdc++.h>
#include <cstdio>
#include<vector>
#include<cstring>
#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,j,tip,k,x,help;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d%d",&tip,&x);
        help=h(x);
        if(tip==1) { it=find(v[help].begin(),v[help].end(),x);
                            if(it==v[help].end()) v[help].push_back(x);}
            else if(tip==2) {
                                   // v[h(x)].erase(find(v[h(x)].begin,v[h(x)].end,x));
                                    it=find(v[help].begin(),v[help].end(),x);
                                    if(it!=v[help].end()) v[help].erase(it);
                                    }
                else
                {
                        it=find(v[help].begin(),v[help].end(),x);
                        if(it!=v[help].end()) printf("1\n");
                            else printf("0\n");
                }
    }
    return 0;
}