Cod sursa(job #765869)

Utilizator proflaurianPanaete Adrian proflaurian Data 9 iulie 2012 17:42:15
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include<stdio.h>
#include<vector>
using namespace std;
int n,h,hv,v,c;
vector<int> ht[100100];
void read(),solve();
int main()
{
	read();
	solve();
	return 0;
}
void read()
{
	freopen("hashuri.in","r",stdin);
	freopen("hashuri.out","w",stdout);
	scanf("%d",&n);
}
void solve()
{
	h=100009;
	vector<int>::iterator it;
	for(;n;n--)
	{
		scanf("%d%d",&c,&v);
		hv=v%h;
		for(it=ht[hv].begin();it!=ht[hv].end();it++)
			if(*it==v)
				break;
		if(c==1)
		{
			if(it==ht[hv].end())ht[hv].push_back(v);
		}
		else
		{
			if(c==2)
			{
				if(it!=ht[hv].end())
				{
					*it=ht[hv].back();
					ht[hv].pop_back();
				}
			}
			else
				(it==ht[hv].end())?printf("0\n"):printf("1\n");
		}
	}
}