Pagini recente » Cod sursa (job #2362031) | Cod sursa (job #2100550) | Cod sursa (job #2020986) | Cod sursa (job #1317485) | Cod sursa (job #1032630)
#include <cstdio>
#include <vector>
#define NMAX 100000
using namespace std;
vector<int> set[NMAX];
int N;
void read(){
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
}
inline int hashCode(int x){
return x % NMAX;
}
inline int isIn(int x, int hash){
vector<int> :: iterator it;
for (it = set[hash].begin(); it != set[hash].end(); it++)
if(*it == x){
return it - set[hash].begin();
}
return -1;
}
inline void add(int x){
int hash = hashCode(x);
int pos = isIn(x, hash);
if (pos < 0){
set[hash].push_back(x);
}
}
inline void remove(int x){
int hash = hashCode(x);
int pos = isIn(x, hash);
if (pos >= 0){
set[hash].erase(set[hash].begin() + pos);
}
}
void apply(int op, int x){
switch(op){
case(1): add(x); break;
case(2): remove(x); break;
case(3): if (isIn(x, hashCode(x)) < 0)
printf("0\n");
else
printf("1\n");
break;
}
}
int main() {
read();
int op, x;
scanf("%d", &N);
for (int i = 1; i <= N; i++){
scanf("%d %d", &op, &x);
apply(op, x);
}
return 0;
}