Cod sursa(job #767434)

Utilizator test_666013Testez test_666013 Data 13 iulie 2012 15:20:14
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.04 kb
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define MOD 666013

vector<int>v[MOD];

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

vector<int>::iterator find(int p,int x){
    vector<int>::iterator it = v[p].begin();
    while( it != v[p].end() )
    {
        if( *it == x ) return it;
        it++;
    }
    return it;
}

void add(int x){
    int p = hash(x);
    if( find(p,x) == v[p].end() )v[p].push_back(x);
}

void remove(int x){
    int p = hash(x);
    vector<int>::iterator it = find(p,x);
    if( it != v[p].end() )v[p].erase(it);
}

bool este(int x){
    int p = hash(x);
    if( find(p,x) != v[p].end() ) return 1;
    return 0;
}

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