Pagini recente » Cod sursa (job #370239) | Cod sursa (job #804828) | Cod sursa (job #2270528) | Cod sursa (job #663329) | Cod sursa (job #1171337)
#include <fstream>
#include <vector>
#define modulo 666013
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
vector<int> hash[modulo];
int n, i, op, x;
vector<int>::iterator hash_find(int x) {
int list=x%modulo;
for (vector<int>::iterator it = hash[list].begin(); it!=hash[list].end(); it++)
if (*it == x)
return it;
return hash[list].end();
}
void hash_insert(int x) {
int list=x%modulo;
if (hash_find(x) == hash[list].end())
hash[list].push_back(x);
}
void hash_delete(int x) {
int list=x%modulo;
vector<int>::iterator it = hash_find(x);
if (it!=hash[list].end())
hash[list].erase(it);
}
int main()
{
f>>n;
for (i=1; i<=n; i++) {
f>>op>>x;
if (op==1)
hash_insert(x);
else if (op==2)
hash_delete(x);
else
if (hash_find(x) != hash[x%modulo].end()) g<<1<<"\n";
else g<<0<<"\n";
}
return 0;
}