Cod sursa(job #1161636)

Utilizator xtreme77Patrick Sava xtreme77 Data 31 martie 2014 12:55:44
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.95 kb
#include <cstdio>
#include <vector>
#define MOD 666013

using namespace std;

int n;
vector <int> hashing[MOD];

void introdu(int val);
void sterge(int val);
int verific(int val);
int main()
{
    int n,i,op,x;
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    scanf("%d",&n);
    for(i=1;i<=n;++i)
    {
        scanf("%d%d",&op,&x);
        if(op==1)introdu(x);
        if(op==2)sterge(x);
        if(op==3)
            printf("%d\n",verific(x));
    }
    return 0;
}
void introdu(int val)
{
    hashing[val%MOD].push_back(val);
}

void sterge(int val)
{
    int poz=val%MOD;
    int nr=hashing[poz].size();
    int i;
    for(i=0;i<nr;++i)
        if(hashing[poz][i]==val)
            hashing[poz][i]=-1;

}

int verific(int val)
{
    int poz=val%MOD;
    int nr=hashing[poz].size();
    int i;
    for(i=0;i<nr;++i)
        if(hashing[poz][i]==val)
            return 1;
    return 0;
}