Cod sursa(job #1060592)

Utilizator cosmin_bobeicaCosmin Bobeica cosmin_bobeica Data 18 decembrie 2013 10:02:09
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.04 kb
#include<cstdio>
#include<list>
using namespace std;
const int MOD=666013;
typedef list<int> hesh;
typedef hesh::iterator hit;
hesh ht[MOD];
int n;

hit find(int x)
{

    for(hit i=ht[x%MOD].begin() ;i!=ht[x%MOD].end() ;i++)
        if(x==*i)
            return i;
    return ht[x%MOD].end();
}

int main()
{
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    int t,x;
    scanf("%d\n",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d %d\n",&t,&x);
        hit j=find(x);
        if(t==1)
        {
            if(j==ht[x%MOD].end())
                ht[x%MOD].push_back(x);
        }
        else
            if(t==2)
            {
                 if(j!=ht[x%MOD].end())
                        ht[x%MOD].erase(j);
            }
            else
                if(t==3)
                {
                    if(j!=ht[x%MOD].end())
                        printf("1\n");
                    else
                        printf("0\n");
                }
    }
    return 0;
}