Pagini recente » Cod sursa (job #1489605) | Cod sursa (job #1709009) | Cod sursa (job #61383) | Cod sursa (job #3260031) | Cod sursa (job #1566281)
#include <fstream>
#include <vector>
using namespace std;
#define MOD 666013
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
vector <int> H[MOD];
vector <int> :: iterator isHash(int x)
{
vector <int> :: iterator it;
int pos = x % MOD;
for (it = H[pos].begin(); it != H[pos].end(); ++it)
if (*it == x) break;
return it;
}
void delHash(int x)
{
vector <int> :: iterator it = isHash(x);
int pos = x % MOD;
if (it == H[pos].end()) // nu l-am gasit
return;
H[pos].erase(it);
}
void insHash(int x)
{
int pos = x % MOD;
if (isHash(x) != H[pos].end()) // l-am gasit
return;
H[pos].push_back(x);
}
int main()
{
int m, tip, x;
fin >> m;
while (m--)
{
fin >> tip >> x;
if (tip == 1)
insHash(x);
else if (tip == 2)
delHash(x);
else
fout << (isHash(x) != H[x % MOD].end()) << '\n';
}
return 0;
}