Cod sursa(job #1265387)

Utilizator priestnoobFMI - Dan Nema priestnoob Data 17 noiembrie 2014 11:20:17
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.03 kb
#include<stdio.h>
#include<vector>

using namespace std;

#define MOD 666013

vector <int> v[MOD];

inline int key(int x)
{
    return x % MOD;
}

inline vector <int>::iterator cautihash (int x)
{
    int ind = key(x);
    vector <int>::iterator it;
    for(it=v[ind].begin();it!=v[ind].end();++it)
    {
        if(*it==x)
            return it;
    }
    return v[ind].end();
}

inline void bagihash (int x)
{
    int ind = key(x);
    if( cautihash(x) == v[ind].end() )
        v[ind].push_back(x);
}

inline void lasihash (int x)
{
    int ind = key(x);
    vector <int>::iterator it=cautihash(x);
    if(it!=v[ind].end())
        v[ind].erase(it);
}

int main()
{
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    int n,op,x;
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
    {
        scanf("%d %d",&op, &x);
    if(op==1)
        bagihash(x);
    if(op==2)
        lasihash(x);
    if(op==3)
        printf("%d\n", cautihash(x) != v[key(x)].end() );
    }
}