Pagini recente » Cod sursa (job #2712547) | Cod sursa (job #2661004) | Cod sursa (job #2688489) | Cod sursa (job #406251) | Cod sursa (job #343788)
Cod sursa(job #343788)
#include <cstdio>
#include <cstdlib>
#include <vector>
const int MOD = 800000;
using namespace std;
vector<int> HT[MOD];
inline vector<int>::iterator find_element(int x) {
int h = x % MOD;
vector<int>::iterator it = HT[h].begin();
while ((it != HT[h].end()) && (*it != x)) ++it;
return it;
}
inline void insert(int x) {
int h = x % MOD;
if (find_element(x) == HT[h].end()) HT[h].push_back(x);
}
inline void remove(int x) {
int h = x % MOD;
vector<int>::iterator it = find_element(x);
if (it != HT[h].end()) HT[h].erase(it);
}
int main() {
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
int N,tip,x;
scanf("%d",&N);
for(;N;N--) {
scanf("%d%d",&tip,&x);
switch(tip) {
case 1: insert(x); break;
case 2: remove(x); break;
case 3: printf("%d\n",find_element(x) != HT[x % MOD].end()); break;
}
}
fclose(stdin);
fclose(stdout);
return 0;
}