Cod sursa(job #1117223)

Utilizator dspMihaiDespotovici Mihai dspMihai Data 23 februarie 2014 11:58:28
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.19 kb
#include <cstdio>
#include <vector>
#define MOD 599110
using namespace std;
vector <unsigned long> v[MOD+5];
unsigned long N,i,crt,l,hash1;
long ok;
int operatie;
int main ()
{
    freopen("hashuri.in", "r", stdin);
    freopen("hashuri.out", "w", stdout);
    scanf("%d", &N);
    for (; N>0; N--)
    {
        scanf("%d %lu", &operatie, &crt); 
        if (operatie==1) 
        {
            hash1=crt%MOD;
            ok=-1;
            l=v[hash1].size();
            for (i=0; i<l && ok<0; i++) if (v[hash1][i]==crt) ok=i;
            if (ok==-1) v[hash1].push_back(crt);
        }
        else if (operatie==2) 
        {
            hash1=crt%MOD;
            ok=-1;
            l=v[hash1].size();
            for (i=0; i<l && ok<0; i++) if (v[hash1][i]==crt) ok=i;
            if (ok!=-1) v[hash1].erase(v[hash1].begin()+ok);
        }
        else if (operatie==3)
        {
            hash1=crt%MOD;
            ok=-1;
            l=v[hash1].size();
            for (i=0; i<l && ok<0; i++) if (v[hash1][i]==crt) ok=i;
            if (ok==-1) printf("0\n");
            else printf("1\n");
        }
    }
 
 
    fclose(stdin); fclose(stdout);
    return 0;
}