Pagini recente » Cod sursa (job #1038335) | Cod sursa (job #1232084) | Cod sursa (job #394146) | Cod sursa (job #826174) | Cod sursa (job #954010)
Cod sursa(job #954010)
#include<fstream>
#include<vector>
#include<algorithm>
#define MOD 10000
#define PI pair<int,int>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
vector < PI > G[MOD];
vector<PI>:: iterator it;
const int SZ=10000;
char input[SZ+1],*in;
int atoi()
{
int nr =0;
for(;!(*in>='0' && *in<='9') && *in;in++);
if(!*in)
{
fin.read(input,SZ);
in=input;
for(;!(*in>='0' && *in<='9') && *in;in++);
}
for(;*in>='0' && *in<='9';in++)
{
nr=nr*10+(*in-'0');
if(!*(in+1))
{
fin.read(input,SZ);
in=input-1;
}
}
return nr;
}
inline void add(int x)
{
int list=x%MOD;
if(G[list].empty())
{
G[list].push_back(make_pair(x,0));
return;
}
it=upper_bound(G[list].begin(),G[list].end(),make_pair(x,0));
int poz=(int)(it-G[list].begin())-1;
if(G[list][poz].first==x && G[list][poz].second==1)
{
G[list][poz].second=0;
return;
}
if(G[list][poz].first!=x)
G[list].insert(it,make_pair(x,0));
}
inline void del(int x)
{
int list=x%MOD;
if(G[list].empty())
return;
it=upper_bound(G[list].begin(),G[list].end(),make_pair(x,0));
int poz=(int)(it-G[list].begin())-1;
if(G[list][poz].first==x && G[list][poz].second==0)
G[list][poz].second=1;
}
int main()
{
int n;
fin.read(input,SZ);
in=input;
n=atoi();
int op,x;
while(n--)
{
op=atoi();
x=atoi();
if(op==1)
{
add(x);
continue;
}
if(op==2)
{
del(x);
continue;
}
fout<<binary_search(G[x%MOD].begin(),G[x%MOD].end(),make_pair(x,0))<<'\n';
}
fin.close();
fout.close();
return 0;
}