Pagini recente » Cod sursa (job #1946636) | Cod sursa (job #517419) | Cod sursa (job #2224942) | Cod sursa (job #879063) | Cod sursa (job #240300)
Cod sursa(job #240300)
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <algorithm>
#include <utility>
#include <string>
#include <functional>
#include <sstream>
#include <fstream>
#include <iostream>
using namespace std;
#define FOR(i,a,b) for (i=a;i<=b;i++)
#define fori(it,v) for (it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define mp make_pair
#define fs first
#define ss second
#define all(c) c.begin(),c.end()
#define pf push_front
#define popb pop_back
#define popf pop_front
FILE *in,*out;
struct nod
{
int v;
nod *next;
};
nod *a[666013];
int hash(int x)
{
return x%666013;
}
void add(int y,int x)
{
nod *i;
for(i=a[y];i!=NULL;i=i->next)
if (i->v==x)
return ;
i=new nod;
i->v=x;
i->next=a[y];
a[y]=i;
}
bool search(int y,int x)
{
nod *i;
for (i=a[y];i!=NULL;i=i->next)
if (i->v==x)
return 1;
return 0;
}
void pop(int y,int x)
{
nod *i,*j;
if (a[y]==NULL)
return ;
if (a[y]->v==x)
{
i=a[y];
a[y]=a[y]->next;
delete i;
return ;
}
for (j=a[y],i=a[y]->next;i!=NULL;i=i->next,j=j->next)
if (i->v==x)
{
j->next=i->next;
delete i;
return;
}
}
int main()
{
int n,i,x,y;
in=fopen("hashuri.in","r");
out=fopen("hashuri.out","w");
fscanf(in,"%d",&n);
FOR(i,1,n)
{
fscanf(in,"%d%d",&x,&y);
if (x==1)
{
add(hash(y),y);
continue;
}
if (x==2)
{
pop(hash(y),y);
continue;
}
fprintf(out,"%d\n",search(hash(y),y));
}
fclose(in);
fclose(out);
return 0;
}