Cod sursa(job #487336)

Utilizator elmercerAlex Mercer elmercer Data 24 septembrie 2010 19:03:31
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb
#include <stdio.h>
#include <math.h>
#include <vector>
#define PRIME 601589

using namespace std;

vector <long> has[PRIME];

long i, n, poz, choice, num, s, j;

int main() {
	freopen("hashuri.in", "r", stdin);
	freopen("hashuri.out", "w", stdout);
	scanf("%ld", &n);
	for (i = 1; i <= n; ++i) {
		poz = -1;
		scanf("%ld %ld", &choice, &num);
		long pri = num % PRIME;
		
		s = has[pri].size();
		for (j = 0; j < s; ++j) {
			if (has[pri][j] == num) {
				poz = j;
				break;
			}
		}
		
		if (choice == 3) {
			if (poz >= 0) 
				printf("1\n");
			else 
				printf("0\n");
			continue;
		}
		
		if (choice == 1) {
			has[pri].push_back(num);
		}
		
		if (choice == 2) {
			if (poz >= 0) {
				has[pri].erase(has[pri].begin() + poz, has[pri].begin() + poz + 1);
			}
		}
	}
	return 0;
}