Cod sursa(job #1018293)

Utilizator ZanarokStefan Mocanu Zanarok Data 29 octombrie 2013 11:15:12
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.95 kb
#include <iostream>
#include <cstdio>
#include <vector>

#define P 19391

using namespace std;

int n;
vector <vector <int> > hesh;

int cauta(int b)
{
    int a=b%P;
    int len=hesh[a].size();
    for(int k=0;k<len;k++)
        if(hesh[a][k]==b)
            return 1;
    return 0;
}

int main()
{
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    cin>>n;
    int a,b,len;
    vector <int> aux;
    hesh.assign(P,aux);
    for(int k=1;k<=n;k++)
    {
        scanf("%d %d",&a,&b);
        if(a==1)
            hesh[b%P].push_back(b);
        else
            if(a==2)
            {
                a=b%P;
                len=hesh[a].size();
                for(int k=0;k<len;k++)
                    if(hesh[a][k]==b)
                        hesh[a].erase(hesh[a].begin()+k);
            }
            else
                if(a==3)
                    cout<<cauta(b);
    }

    return 0;
}