Cod sursa(job #2037610)

Utilizator ana_dariaAna Daria Hendoreanu ana_daria Data 12 octombrie 2017 16:22:42
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int M=666013;
int hashh(int k)
{
    return k%M;
}
vector <int> H[M+5];
int main()
{
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    int n,op,x,i,a;
    vector<int>::iterator it;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d%d",&op,&x);
        if(op==1)
        {
            a=hashh(x);
            it=find(H[a].begin(), H[a].end(), x);
            if(it==H[a].end())
                H[a].push_back(x);
        }
        else if(op==2)
        {
            a=hashh(x);
            it=find(H[a].begin(),H[a].end(),x);
            if(it!=H[a].end())
                H[a].erase(it);
        }
        else if(op==3)
        {
            a=hashh(x);
            it=find(H[a].begin(),H[a].end(),x);
            if(it!=H[a].end()) printf("1\n");
            else printf("0\n");
        }
    }
    return 0;
}