Pagini recente » Monitorul de evaluare | Cod sursa (job #2642320) | Cod sursa (job #303920) | Cod sursa (job #2003390) | Cod sursa (job #933116)
Cod sursa(job #933116)
#include<fstream>
#include<vector>
#include<algorithm>
#define MOD 10000
using namespace std;
vector <int> G[MOD];
vector<int>:: iterator it;
short list;
inline void add(int x)
{
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)
{
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,choice,x;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
fin>>n;
while(n--)
{
fin>>choice>>x;
list=x%MOD;
if(choice==1)
{
add(x);
continue;
}
if(choice==2)
{
del(x);
continue;
}
fout<<binary_search(G[list].begin(),G[list].end(),x)<<'\n';
}
fin.close();
fout.close();
return 0;
}