Pagini recente » Cod sursa (job #973565) | Cod sursa (job #1965249) | Cod sursa (job #251116) | Cod sursa (job #1576955) | Cod sursa (job #2745786)
#include <fstream>
#include <vector>
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
int n,cod,x;
int prim = 666013;
vector <int> H[666013];
int cauta(int x)
{
int h = x % prim;
for(int i=0; i<H[h].size(); i++)
if(H[h][i] == x)
return 1;
return 0;
}
void adauga(int x)
{
int h = x % prim;
if(cauta(x) == 0)
H[h].push_back(x);
}
void sterge(int x)
{
int h = x % prim;
for(int i=0; i<H[h].size(); i++)
if(H[h][i] == x)
{
H[h][i] = H[h][H[h].size()-1];
H[h].pop_back();
break;
}
}
int main()
{
in >> n;
for(int i=1; i<=n; i++)
{
in >> cod >> x;
if(cod == 1)
adauga(x);
else if(cod == 2)
sterge(x);
else if(cod == 3)
out << cauta(x) << "\n";
}
in.close();
out.close();
return 0;
}