Cod sursa(job #2037590)

Utilizator IoanZioan zahiu IoanZ Data 12 octombrie 2017 16:03:59
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.86 kb
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int M=666013;

vector <int> h[M+5];
vector <int>::iterator it;

int hashh(int k)
{
    return k%M;
}

int main()
{
    int n,i,c,nr,x;
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    scanf("%d",&n);
    for (i=1;i<=n;i++)
    {
        scanf("%d%d",&c,&nr);
        x=hashh(nr);
        it=find(h[x].begin(),h[x].end(),nr);
        if (c==1)
        {

            if (it==h[x].end())
                h[x].push_back(nr);
        }
        else
            if (c==2)
        {
            if (it!=h[x].end())
                h[x].erase(it);
        }
        else
        {
            if (it!=h[x].end())
                printf("1\n");
            else
                printf("0\n");
        }
    }
    return 0;
}