Cod sursa(job #1480031)

Utilizator cremarencodianaCremarenco Diana cremarencodiana Data 1 septembrie 2015 21:52:18
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.06 kb
#include <cstdio>
# include <vector>
using namespace std;

vector<int> v[666020];

int i,n,op,x;
bool findHash(int x)
{
    int key = x%666013;
    for (int i=0; i<v[key].size(); i++)
        if (v[key][i]==x)
        return true;
    return false;
}

void deleteHash(int x)
{
    int key = x%666013;
    for (int i=0; i<v[key].size(); i++)
        if (v[key][i]==x) v[key].erase(v[key].begin()+i, v[key].begin()+i+1);
}
void insertHash(int x)
{
    int key = x%666013;
    if (v[key].size() == 0)
        v[key].push_back(x);
    else
        if (!findHash(x))
           v[key].push_back(x);
}

int main()
{
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);

    scanf("%d\n",&n);
    for (i=1; i<=n; i++)
    {
        scanf("%d %d\n",&op,&x);
        if (op==1)
            insertHash(x);
        if (op==2)
            deleteHash(x);
        if (op==3)
        {
            if (findHash(x))
                printf("%d\n", 1);
            else
                printf("%d\n", 0);
        }
    }
}