Pagini recente » Cod sursa (job #3211002) | Cod sursa (job #2849479) | Cod sursa (job #2198730) | Cod sursa (job #879685) | Cod sursa (job #869833)
Cod sursa(job #869833)
#include<vector>
#include<cstdio>
using namespace std;
const int MOD = 666013;
vector <int> table[MOD];
void adauga(int x){
int pos = x % MOD;
vector <int>::iterator it, end=table[pos].end();
for(it=table[pos].begin() ; it!=end ; ++it)
{
if(*it==x)
return;
}
table[pos].push_back(x);
}
void elim(int x){
int pos = x % MOD;
vector <int>::iterator it, end=table[pos].end();
for(it=table[pos].begin() ; it!=end ; ++it)
if(*it==x)
{
table[pos].erase(it);
return;
}
}
bool exists(int x){
int pos = x % MOD;
vector <int>::iterator it, end=table[pos].end();
for(it=table[pos].begin() ; it!=end ; ++it)
if(*it==x)
return true;
return false;
}
int main(){
FILE *in=fopen("hashuri.in","r"), *out=fopen("hashuri.out","w");
int q, type, val;
fscanf(in, "%d\n", &q);
for(int i=1; i<=q; i++){
fscanf(in, "%d %d\n", &type, &val);
if(type==1)
adauga(val);
else if(type==2)
elim(val);
else if(type==3)
fprintf(out, "%d\n", exists(val));
}
return 0;
}