Pagini recente » Cod sursa (job #2221357) | Cod sursa (job #2185820) | Cod sursa (job #238399) | Cod sursa (job #111642) | Cod sursa (job #600397)
Cod sursa(job #600397)
#include <iostream>
#include <fstream>
#include <vector>
#define m 660001
using namespace std;
vector<int> g[m];
int h(int x)
{
return x%m;
}
vector<int>::iterator fnd(int x)
{
int l=h(x);
vector<int>::iterator it;
for(it = g[l].begin();it != g[l].end(); ++it)
if(*it == x) return it;
return g[l].end();
}
void add(int x)
{
if(fnd(x) == g[h(x)].end())
{
g[h(x)].push_back(x);
}
}
void eras(int x)
{
vector<int>::iterator it=fnd(x);
if(it != g[h(x)].end())
g[h(x)].erase(it);
}
int main()
{
int n, x, y;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
in >> n;
for(;n;--n){
in >> x >>y;
if(x == 1){//adauga
add(y);
}else if(x == 2){//sterge
eras(y);
}else{//find
out << (fnd(y) != g[h(y)].end()) << '\n';
}
}
in.close();
out.close();
return 0;
}