Cod sursa(job #804065)

Utilizator MKLOLDragos Ristache MKLOL Data 28 octombrie 2012 19:47:27
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.81 kb
#include<stdio.h>
#include<vector>
#define MOD 666013
using namespace std;


vector<int> g[700000];

int hash(int x)
{
    return x%MOD;
}
int find(int x)
{
int y=hash(x);
for(int i=0;i<g[y].size();++i)
    if(g[y][i]==x)
        return 1;
return 0;
}
int add(int x)
{
g[hash(x)].push_back(x);
}
int del(int x)
{
int y=hash(x);
    for(int i=0;i<g[y].size();++i)
        if(g[y][i]==x)
            g[y].erase(g[y].begin() + i);
    return 1;
}

int main()
{
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
int N,x,y;
scanf("%d",&N);
for(int i=1;i<=N;++i)
{
    scanf("%d%d",&x,&y);
    if(x==1)
    {
    if(!find(y))
        add(y);
    }
    if(x==3)
        printf("%d\n",find(y));
    if(x==2)
        if(find(y))
            del(y);
}

return 0;

}