Cod sursa(job #615672)

Utilizator nashnash mit nash Data 10 octombrie 2011 15:24:47
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.91 kb


#include <cstdio>
#include <list>

using namespace std;

#define NMAX 200001

int n , val , op;

list<int> vec[ NMAX ] ;
list<int>::iterator it;

int main() {

	freopen("hashuri.in","r",stdin);
	freopen("hashuri.out","w",stdout);

	scanf("%d",&n);

	for(int  i = 1 ; i <= n ; i++) {

		scanf("%d %d",&op,&val);

		switch( op ) {
		
		case 1:
			{
			int poz = val % NMAX;
			int ok1 = 0;
			for(it = vec[ poz ].begin() ; it != vec[ poz ].end() ; it++)
				if( *it == val )
					ok1 = 1;
			if(!ok1) vec[ val % NMAX ].push_back(val);
			break;
			}
		case 2: {
			int poz = val % NMAX;
			vec[ poz ].remove( val );
			break;
		}
		case 3:
			{
			int poz = val % NMAX;
			int ok = 0;
			for(it = vec[ poz ].begin() ; it != vec[ poz ].end() ; it++)
				if( *it == val ) {
					printf("1\n");
					ok = 1;
				}
			if(!ok) printf("0\n");
			break;
			}
		}
	}

	return 0;
}