Cod sursa(job #771284)

Utilizator a96tudorAvram Tudor a96tudor Data 25 iulie 2012 14:10:07
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.99 kb
#include<cstdio>
#include<vector>
#define pb push_back
#define Mod 666013
using namespace std;
vector <int> H[Mod];
vector <int> :: iterator it;
int i,n,IND,op,x;

void if_x (int x)
{
    bool ok=false;
    for (it=H[IND].begin();it<H[IND].end();it++)
        if (*it==x) { ok=true;
                      break;
                        }
    printf("%d\n",ok);
}

void push_x (int x)
{
    if (it==H[IND].end()) H[IND].pb(x);
}

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

vector <int> :: iterator find_x (int x)
{
    for(it= H[IND].begin(); it!=H[IND].end(); it++)
        if (*it==x) return it;
    return it;
}

int main()
{
    freopen ("hashuri.in","r",stdin);
    freopen ("hashuri.out","w",stdout);
    scanf("%d",&n);
    for (i=1;i<=n;i++)
    {
        scanf("%d %d",&op,&x);
        IND=x%Mod;
        it=find_x(x);
        if (op==1) push_x(x);
        if (op==2) del_x(x);
        if (op==3) if_x(x);
    }
    return 0;
}