Cod sursa(job #763642)

Utilizator test666013Testez test666013 Data 2 iulie 2012 19:26:18
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 kb
#include <cstdio>
#include <set>
#include <algorithm>
using namespace std;
#define MOD 666013

set<int>g[MOD];

inline int hash(int x){ return x%MOD; }

bool find(int x){
    int p = hash(x);
    return g[p].find(x) != g[p].end();
}

void add(int x){
    int p = hash(x);
    g[p].insert(x);
}


void remove(int x){
    int p = hash(x);
    g[p].erase(x);
}

int main(){
    int m,c,x;
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
        scanf("%d",&m);
        while(m--)
        {
            scanf("%d %d",&c,&x);
            switch(c){
                case 1: add(x); break;
                case 2: remove(x); break;
                case 3: printf("%d\n",find(x)); break;
            }
        }
    return 0;
}