Cod sursa(job #616542)

Utilizator razvan2006razvan brezulianu razvan2006 Data 12 octombrie 2011 20:08:59
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.07 kb
#include<stdio.h>
#include<stdlib.h>
#define PRIM 999979

long i, j, n, LgVec[PRIM + 1], x, y, ok;
long * vec[PRIM + 1];
	
int main()
{
	freopen("hashuri.in", "rt", stdin);
	freopen("hashuri.out", "wt", stdout);
		
	scanf("%ld", &n);
	
	for(i = 1; i <= n; i++)
	{
		scanf("%ld %ld", &x, &y);
		
		if(x == 1)
			LgVec[y % PRIM]++;
	}
	
	freopen("hashuri.in", "rt", stdin);
	
	scanf("%ld", &n);
	
	for(i = 0; i < PRIM; i++)
		if(LgVec[i] != 0)
		{
			vec[i] = (long*) malloc(LgVec[i] * sizeof(long));
			LgVec[i] = 0;
		}
	
	for(i = 1; i <= n; i++)
	{
		scanf("%ld %ld", &x, &y);
		
		if(x == 1)
		{
			vec[y % PRIM][LgVec[y % PRIM]] = y;
			LgVec[y % PRIM]++;
		}
		
		if(x == 2)
		{
			for(j = 0; j < LgVec[y % PRIM]; j++)
				if(vec[y % PRIM][j] == y)
					vec[y % PRIM][j] = -1;
		}
		
		if(x == 3)
		{
			ok = 1;
			for(j = 0; j < LgVec[y % PRIM] && ok == 1; j++)
				if(vec[y % PRIM][j] == y)
				{				
					printf("1\n");
					ok = 0;
				}			
			
			if(ok == 1)
				printf("0\n");
		}
	}
	
	fclose(stdout);
	
	return 0;
}