Pagini recente » Cod sursa (job #856635) | Cod sursa (job #685466) | Cod sursa (job #680474) | Cod sursa (job #1740005) | Cod sursa (job #953988)
Cod sursa(job #953988)
#include<fstream>
#include<vector>
#include<algorithm>
#define MOD 10000
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
vector <int> G[MOD];
vector<int>:: iterator it;
const int SZ=10000;
char input[SZ],*in;
int atoi()
{
int nr =0;
for(;!(*in>='0' && *in<='9');in++);
for(;*in>='0' && *in<='9';in++)
{
nr=nr*10+(*in-'0');
if(!*(in+1))
{
fin.read(input,SZ);
in=input;
}
}
return nr;
}
inline void add(int x)
{
int list=x%MOD;
if(G[list].empty())
{
G[list].push_back(x);
return;
}
it=upper_bound(G[list].begin(),G[list].end(),x);
int poz=(int)(it-G[list].begin())-1;
if(G[list][poz]!=x)
G[list].insert(it,x);
}
inline void del(int x)
{
int list=x%MOD;
if(G[list].empty())
return;
it=upper_bound(G[list].begin(),G[list].end(),x);
int poz=(int)(it-G[list].begin())-1;
if(G[list][poz]==x)
G[list].erase(G[list].begin()+poz);
}
int main()
{
int n;
fin.read(input,SZ);
in=input;
fin.close();
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(),x)<<'\n';
}
fout.close();
return 0;
}