Cod sursa(job #904904)

Utilizator tudgal1001Profir Tudor tudgal1001 Data 4 martie 2013 23:19:50
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 1.05 kb
#include<cstdio>
#include<list>
#define M 666013
using namespace std;

list <int> a[M+5];
list <int>::iterator it;

list <int>::iterator loc (int x)
{
    list <int>::iterator itt;
    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 (!a[x%M].size())
        a[x%M].push_back(x);
    else
    {
        it=loc(x);
        if (it!=a[x%M].end())
            a[x%M].push_back(x);
    }
}

void erase (int x)
{
    if (a[x%M].size())
    {
        it=loc(x);
        if (it!=a[x%M].end())
            a[x%M].erase(it);
    }
}

int multime (int x)
{
    if (a[x%M].size())
        if (it!=a[x%M].end())
            return 1;
    return 0;
}

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",multime(x));
    }
    return 0;
}