Cod sursa(job #390444)

Utilizator alexandru92alexandru alexandru92 Data 3 februarie 2010 19:23:57
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.97 kb
//      hash.cpp
//      
//      Copyright 2010 SpeeDemon <virtualdemon@ubuntu>
//      
//      This program is free software; you can redistribute it and/or modify
//      it under the terms of the GNU General Public License as published by
//      the Free Software Foundation; either version 2 of the License, or
//      (at your option) any later version.
//      
//      This program is distributed in the hope that it will be useful,
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//      GNU General Public License for more details.
//      
//      You should have received a copy of the GNU General Public License
//      along with this program; if not, write to the Free Software
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//      MA 02110-1301, USA.
#include <fstream>
#include <cstdlib>
#define Modulo   3000523

/*
 * 
 */
using namespace std;
struct vertex
{
	 int info;
	 vertex* next;
} *L[Modulo];
typedef vertex *list;
inline void push( int pos, int y )
{list q;
	if( y >= Modulo && L[pos] )
	{
		for( q=L[pos]; q; q=q->next )
			if( y == q->info )
				return;
	}
	q=new vertex;
	q->info=y;
	q->next=L[pos];
	L[pos]=q;
}
inline void pop( int pos, int y )
{
	if( L[pos] )
	{
		list q;
		if( y == L[pos]->info )
		{
			q=L[pos];
			L[pos]=q->next;
			delete q;
			return;
		}
		for( q=L[pos]; q->next; q=q->next )
			if( y == q->next->info )
				break;
		if( q->next && y == q->next->info )
		{
			list p=q->next;
			q->next=p->next;
			delete p;
		}
	}
}
inline bool find( int pos, int y )
{
	for( list q=L[pos]; q; q=q->next )
		if( y == q->info )
			return true;
	return false;
}
int main()
{
	int n, x, y, pos;
	ifstream in("hashuri.in");
	ofstream out("hashuri.out");
	in>>n;
	for( ;n; --n )
	{
		in>>x>>y;
		pos=y%Modulo;
		switch( x )
		{
			case 1: push( pos, y ); break;
			case 2: pop( pos, y ); break;
			case 3: out<<(find( pos, y ) )<<'\n'; break;
		}
	}
	return 0;
}