Pagini recente » Cod sursa (job #2799052) | Cod sursa (job #2966471) | Cod sursa (job #2509531) | Cod sursa (job #2844146) | Cod sursa (job #3146507)
#include <iostream>
#include <fstream>
#include <vector>
#define MOD 666013
using namespace std;
ifstream fin ("hashuri.in");
ofstream fout ("hashuri.out");
vector<int> hashh[MOD];
int n;
void add(int x)
{
hashh[x%MOD].push_back(x);
}
void remove(int x)
{
for (int i = 0; i < hashh[x%MOD].size(); i++)
{
if (hashh[x%MOD][i] == x)
{
hashh[x%MOD][i] = hashh[x%MOD][hashh[x%MOD].size()-1];
hashh[x%MOD].pop_back();
return;
}
}
}
int exists(int x)
{
for (int i = 0; i < hashh[x%MOD].size(); i++)
if (hashh[x%MOD][i] == x)
return 1;
return 0;
}
int main()
{
fin >> n;
for (int i = 0; i < n; i++)
{
int op, x;
fin >> op >> x;
if (op == 1) add(x);
else if (op == 2) remove(x);
else if (op == 3) fout << exists(x) << "\n";
}
return 0;
}