Cod sursa(job #654800)

Utilizator nautilusCohal Alexandru nautilus Data 30 decembrie 2011 22:14:51
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.81 kb
#include<fstream>
#include<vector>
using namespace std;
#define PRIM 666013

int n;
int op,x,rest;
vector<int> T[PRIM];

int search()
{
 int i;
 for (i=0; i<(int)T[rest].size(); ++i)
	 if ( T[rest][i] == x ) 
		 return i;
 return -1;
}

void insert()
{
 if ( search() == -1 )
	 T[rest].push_back( x );
}

void erase()
{
 if ( search() != -1 )
	 T[rest].erase( T[rest].begin() + search() );
}

void read_write()
{
 int i;
 ifstream fin("hashuri.in");
 ofstream fout("hashuri.out");

 fin>>n;
 for (i=1; i<=n; ++i)
	{
	 fin>>op>>x;
	 rest = x % PRIM;
	 if (op == 1)
		 insert(); else
		 if (op == 2)
			 erase(); else
			 if ( search() != -1 )
				 fout<<"1"<<'\n';else
				 fout<<"0"<<'\n';
	}

 fin.close();
 fout.close();
}


int main()
{
 read_write();

 return 0;
}