Cod sursa(job #732221)

Utilizator Stefana_fFratean Stefana Stefana_f Data 9 aprilie 2012 22:18:04
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.94 kb
#include <stdio.h>
#include <vector>
#define val 666013
using namespace std;

int n;
vector <int> mul[val];

inline vector<int>::iterator cautare(int x){
	vector <int>::iterator it;
	int pos = x % val;
	for(it = mul[pos].begin(); it != mul[pos].end(); ++it)
		if(*it == x)
			return it;
	return mul[pos].end();
}

inline void inserare(int x){
	int pos = x % val;
	if(cautare(x) == mul[pos].end())
		mul[pos].push_back(x);
}

inline void stergere(int x){
	int pos = x % val;
	vector<int>::iterator it = cautare(x);
	if (it != mul[pos].end())
		mul[pos].erase(it);
}

int main(){
	int operatie, x;
	freopen("hashuri.in", "r", stdin);
	freopen("hashuri.out", "w", stdout);
	for(scanf("%d", &n); n; --n){
		scanf("%d %d", &operatie, &x);
		if(operatie == 1){
			inserare(x);
			continue;
		}
		if(operatie == 2){
			stergere(x);
			continue;
		}
		printf("%d\n", cautare(x) != mul[x % val].end());
	}
	return 0;
}