Cod sursa(job #640530)

Utilizator alex_mircescuAlex Mircescu alex_mircescu Data 25 noiembrie 2011 22:26:01
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.18 kb
#include <stdio.h>
#include <vector>

#define P 224057

using namespace std;

long n, i, t, v;
vector <long> V[1000010];

inline vector<long>::iterator find_value(long x) {
    long aux = v % P;
    vector<long>::iterator it;

    for (it = V[aux].begin(); it != V[aux].end(); ++it)
        if (*it == x)
            return it;
		
    return V[aux].end();
}

int main() {
	freopen("hashuri.in", "r", stdin);
	freopen("hashuri.out", "w", stdout);
	
	scanf("%ld", &n);
	for (i = 1; i <= n; ++i) {
		scanf("%ld %ld", &t, &v);
		if (t == 1) {
			long aux = v % P;
			long S = V[aux].size();
			long ok = 0;
			for (long j = 0; j < S; ++j)
				if (V[aux][j] == v) {
					ok = 1;
					break;
				}
			if (!ok) V[aux].push_back(v);
		}
		if (t == 2) {
			long aux = v % P;			
			vector<long>::iterator it = find_value(v);
			
			if (it != V[aux].end())
				V[aux].erase(it);
			
			//V[aux].erase(v);
		}
		if (t == 3) {
			long aux = v % P;
			long S = V[aux].size();
			long ok = 0;
			for (long j = 0; j < S; ++j)
				if (V[aux][j] == v) {
					printf("1\n");
					ok = 1;
					break;
				}			
			if (ok == 0) printf("0\n");
		}
	}
	return 0;
}