Cod sursa(job #905238)

Utilizator tudgal1001Profir Tudor tudgal1001 Data 5 martie 2013 18:04:18
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.8 kb
#include<cstdio>
#include<list>
#define M 666013
using namespace std;

list <int> a[M];

list <int>::iterator loc (int x)
{
    list <int>::iterator it;
    for (it=a[x%M].begin(); it!=a[x%M].end(); ++it)
        if (*it==x)
            return it;
    return a[x%M].end();
}

void add (int x)
{
    if (loc(x)==a[x%M].end())
        a[x%M].push_back(x);
}

void erase (int x)
{
    list<int>::iterator it=loc(x);
    if (it!=a[x%M].end())
        a[x%M].erase(it);
}

int main ()
{
    int n,tip,x;
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    scanf("%d",&n);
    while (n--)
    {
        scanf("%d%d",&tip,&x);
        if (tip==1)
            add(x);
        else if (tip==2)
            erase(x);
        else
            printf("%d\n",loc(x)!=a[x%M].end());
    }
    return 0;
}