Pagini recente » Cod sursa (job #763548) | Cod sursa (job #232494) | Cod sursa (job #436951) | Cod sursa (job #2859455) | Cod sursa (job #731920)
Cod sursa(job #731920)
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <fstream>
using namespace std;
#define HMAX 666013
list <int> a[HMAX];
int N,op,x;
int find(int x){
int p=x%HMAX;
for (list<int>:: iterator it=a[p].begin(); it!=a[p].end(); it++)
if (*it==x)
return 1;
return 0;
}
void add(int x){
if (find(x))
return;
a[x%HMAX].push_back(x);
}
void remove(int x){
int p = x % HMAX;
for (list<int> :: iterator it = a[p].begin(); it != a[p].end(); it++)
if (*it == x){
*it = *(--a[p].end());
a[p].pop_back();
return;
}
}
int main(){
//freopen("hashuri.in", "r", stdin);
//freopen("hashuri.out", "w", stdout);
//scanf("%d", &N);
ifstream f ("hashuri.in");
ofstream g ("hashuri.out");
f>>N;
for (int i=0; i<N; i++){
//scanf("%d %d", &op, &x);
f>>op>>x;
if (op==1)
add(x);
else
if (op==2)
remove(x);
else
//printf("%d\n", find(x));
g<<find(x)<<endl;
}
return 0;
}