Pagini recente » Cod sursa (job #452537) | Cod sursa (job #1620208) | Cod sursa (job #2548539) | Cod sursa (job #870537) | Cod sursa (job #867977)
Cod sursa(job #867977)
#include<stdio.h>
#include<vector>
using namespace std;
FILE *in,*out;
void adaug (int val);
void sterg (int val);
bool verific (int val);
const int mod=666013;
std::vector<int>hash[1000001];
int n,tip,vale;
int main(void)
{
in=fopen("hashuri.in","rt");
out=fopen("hashuri.out","wt");
fscanf(in,"%d",&n);
for(int i=1;i<=n;++i)
{
fscanf(in,"%d",&tip);
fscanf(in,"%d",&vale);
if(tip==1)
adaug(vale);
else
if(tip==2)
sterg(vale);
else
if(verific(vale))
fprintf(out,"1\n");
else
fprintf(out,"0\n");
}
fclose(in);
fclose(out);
return 0;
}
void adaug (int val)
{
int pos=val %mod;
std::vector<int>::iterator it;
for(it=hash[pos].begin();it!=hash[pos].end();++it)
if(*it==val)
return;
hash[pos].push_back(val);
}
void sterg (int val)
{
int pos=val %mod;
std::vector<int>::iterator it;
for(it=hash[pos].begin();it!=hash[pos].end();++it)
if(*it==val)
{
hash[pos].erase(it);
return;
}
}
bool verific (int val)
{
int pos=val % mod;
std::vector<int>::iterator it;
for(it=hash[pos].begin();it!=hash[pos].end();++it)
if(*it==val)
return true;
return false;
}