Cod sursa(job #781575)

Utilizator my666013Test Here my666013 Data 24 august 2012 17:53:32
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.88 kb
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define Mod 666013

vector<int>g[Mod];

int hash(int x){ return x%Mod; }
bool is(int x)
{
    int p = hash(x);
    for(int i=0;i<g[p].size();i++) if(g[p][i] == x)return 1;
    return 0;
}
void insert(int x){
    int p = hash(x);
    if(!is(x))g[p].push_back(x);
}
void erase(int x){
    int p = hash(x);
    vector<int>::iterator it = g[p].begin();
    while( it != g[p].end() )
    {
        if( *it == x )
        {
            g[p].erase(it);
            return;
        }
        it++;
    }
}

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: insert(x); break;
        case 2: erase(x); break;
        case 3: printf("%d\n",is(x)); break;
        }
    }

}