Cod sursa(job #631663)

Utilizator stanescu_teodorStanescu Teodor stanescu_teodor Data 9 noiembrie 2011 14:01:23
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include <fstream>
#include <vector>
#define MOD 666013
#define pb push_back
using namespace std;

vector <int> v[100000];
vector <int>::iterator it;
int i,o,x,n;
ifstream f ("hashuri.in");
ofstream g ("hashuri.out");
void insertv (int x)
{
	bool ok=true;
	int ind = x % MOD;
	for (it=v[ind].begin(); it!=v[ind].end(); it++)
		if (*it == x) ok=false;
	if (ok) v[ind].pb(x);
}

void deletev (int x)
{
	int ind = x % MOD;
	for (it=v[ind].begin(); it!=v[ind].end(); it++)
		if (*it == x) 
		{
			v[ind].erase (it);
			break;
		}
}

void afis (int x)
{
	bool ok=false;
	int ind = x % MOD;
	for (it=v[ind].begin(); it!=v[ind].end(); it++)
		if (*it == x) ok=true;
	if (ok) g << "1"<<endl;
		else g <<"0"<<endl;
}

int main ()
{
	f >> n;
	for (i=1; i<=n; i++)
	{
		f >> o >> x;
		if (o==1) 
			insertv (x);
		if (o==2)
			deletev (x);
		if (o==3) 
			afis (x);
	}
	return 0;
}