Cod sursa(job #632120)

Utilizator rzvrzvNicolescu Razvan rzvrzv Data 10 noiembrie 2011 13:45:47
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.84 kb
#include<cstdio>
#include<vector>
#define Mod 666013

using namespace std;
int n,x,op,ind,i;
vector <int> H[Mod];
vector <int>::iterator it;

vector <int>::iterator find_v(int x ){

    for (it=H[ind].begin(); it!=H[ind].end();it++)
    if (*it==x)
        return it;
    return it;
}

void insert_v(int x)
{
    if(it==H[ind].end()) H[ind].push_back(x);
}

void erase_v(int x)
{
    if (it!=H[ind].end()) H[ind].erase(it);
}

void write_v(int x)
{
    if (it == H[ind].end()) printf("0\n"); else printf("1\n");
}

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

    scanf("%d\n",&n);
    for (i=1;i<=n;i++)
	{
		scanf("%d %d",&op, &x);
		ind=x%Mod;
		it=find_v(x);
		if (op==1) insert_v(x);
        if (op==2) erase_v(x);
        if (op==3) write_v(x);
	}
	return 0;
}