Pagini recente » Cod sursa (job #2768116) | Rating Dascal Cezar (Petrucci) | Cod sursa (job #1457611) | Cod sursa (job #423283) | Cod sursa (job #1198185)
#include<fstream>
#include<algorithm>
#define MOD 666013
using namespace std;
typedef struct lnod {
int info;
lnod *next;
}*nod;
int n,tip,x;
nod a[666018];
bool u;
void add(int x,nod &y) {
nod p=new lnod;
p->info=x;
p->next=y;
y=p;
}
void del(int x) {
nod p=a[x%MOD],r;
while(p)
if(p->info==x) if(p==a[x%MOD]) if(p->next==NULL) { a[x%MOD]=NULL;delete p; return; }
else { a[x%MOD]=p->next;delete p; return; }
else {
r->next=p->next;
r=r->next;
delete p;
return;
}
else r=p,p=p->next;
}
bool find(int x) {
nod p;
for(p=a[x%MOD];p;p=p->next)
if(p->info==x) return 1;
return 0;
}
int main()
{
ifstream cin("hashuri.in");
ofstream cout("hashuri.out");
cin>>n;
while(n--)
{
cin>>tip>>x;
u=find(x);
if(tip==1 && !u) add(x,a[x%MOD]);
if(tip==2 && u) del(x);
if(tip==3) cout<<u<<'\n';
}
return 0;
}