Cod sursa(job #527616)

Utilizator Catah15Catalin Haidau Catah15 Data 31 ianuarie 2011 22:24:03
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.83 kb
#include <fstream>
#include <vector>
#define MOD 666013
using namespace std;

vector <int> v[MOD + 3];
int dim[MOD + 3];

int search(long long x)
{
	for(int i = 0; i < dim[x % MOD]; ++i)
		if(v[x % MOD][i] == x)
			return (i + 1);
	
	return 0;
}

void del(long long x)
{
	if(search(x))
		v[x % MOD][search(x) - 1] = -1;
	
}

void add(long long x)
{
	if(!search(x))
	{	
		v[x % MOD].push_back(x);
		++dim[x % MOD];
	}
}

int main()
{
	ifstream f("hashuri.in");
	ofstream g("hashuri.out");
	
	int n;
	
	f >> n;
	
	
	for(int i = 1; i <= n; ++i)
	{
		
		long long x;
		short type;
		
		f >> type >> x;
		
		if(type == 1)
			add(x);
		
		if(type == 2)
			del(x);
		
		if(type == 3)
			if(search(x))
				g << "1\n";
			else 
				g << "0\n";
	}
	
	
	f.close();
	g.close();
	
	return 0;
	
}