Cod sursa(job #532287)

Utilizator DuxarFII-Stefan-Negrus Duxar Data 11 februarie 2011 11:53:43
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include<cstdio>
#include<vector>
#define PRM 499979
#define IT vector < int > :: iterator 
using namespace std;

vector < vector < int > > a(PRM);

void solve();
void op1(int x);
void op2(int x);
IT op3(int x);

int main()
{
	freopen("hashuri.in","r",stdin);
	freopen("hashuri.out","w",stdout);
	solve();
	return 0;
}

void solve()
{
	IT it;
	int N,c,x;
	scanf("%d",&N);
	while(N)
	{
		scanf("%d%d",&c,&x);
		if (c==1)
			op1(x);
		if (c==2) 
			op2(x);
		if (c==3)
		{
			it=op3(x);
			printf("%d\n",it!=a[x%PRM].end()); 
		}
		--N;
	}
}

void op1(int x)
{
	IT it;
	it=op3(x);
	if (it==a[x%PRM].end())  
		a[x%PRM].push_back(x);
}

void op2(int x)
{
	IT it1,it2;
	int r=x%PRM;
	it1=op3(x);
	if (it1!=a[r].end())
	{
		it2=a[r].end();
		--it2;
		swap(*it1,*it2);
		a[r].pop_back();
	}
}

IT op3(int x)
{
	IT it;
	int r=x%PRM;
	for (it=a[r].begin();it!=a[r].end();++it)
		if (*it==x) return it;
	return it;
}