Cod sursa(job #609804)

Utilizator mihai995mihai995 mihai995 Data 23 august 2011 14:23:05
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.83 kb
#include <fstream>
#include <list>
using namespace std;

const int mod=666013;
list<int> a[mod];

ifstream in("hashuri.in");
ofstream out("hashuri.out");

list<int>::iterator find(int x)
{
    int L=x%mod;
    for (list<int>::iterator i=a[L].begin();i!=a[L].end();i++)
        if (*i==x)
            return i;
    return a[L].end();
}

void push(int x)
{
    int L=x%mod;
    if (find(x)==a[L].end())
        a[L].push_back(x);
}

void pop(int x)
{
    int L=x%mod;
    list<int>::iterator i=find(x);
    if (i!=a[L].end())
        a[L].erase(i);
}

int main()
{
    int n,q,x;
    in>>n;
    while (n--)
    {
        in>>q>>x;
        if (q==1)
            push(x);
        if (q==2)
            pop(x);
        if (q==3)
            out<<(find(x)!=a[x%mod].end())<<"\n";
    }
    return 0;
}