Cod sursa(job #1216864)

Utilizator UMihneaUngureanu Mihnea UMihnea Data 5 august 2014 23:10:19
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.19 kb
#include<cstdio>
#include<vector>
#define H 71993
using namespace std;
vector<int> A[H];
vector<int>::iterator hashFind(int);
void hashAdd(int), hashRemove(int);
int x,t,i,n;
int main()
{
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    scanf("%d",&n);
    for(;n;n--)
    {
        scanf("%d%d",&t,&x);
        if(t == 1)
        {
            hashAdd(x);
            continue;
        }
        if(t == 2)
        {
            hashRemove(x);
            continue;
        }
        if(t == 3)
        {
            if(hashFind(x) == A[x%H].end())
                printf("0\n");
            else
                printf("1\n");
            continue;
        }
    }
    return 0;
}
vector<int>::iterator hashFind(int X)
{
    int L = X % H;
    vector<int>::iterator it;
    for(it = A[L].begin(); it != A[L].end(); it ++)
        if(*it == X)
            return it;
    return A[L].end();
}
void hashAdd(int X)
{
    int L = X % H;
    if(hashFind(X) == A[L].end())
        A[L].push_back(X);
}
void hashRemove(int X)
{
   int L = X % H;
   vector<int>::iterator it;
   it = hashFind(X);
   if(it != A[L].end())A[L].erase(it);
}