Cod sursa(job #763643)

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

vector<int>g[MOD];

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

bool find(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 add(int x){
    int p = hash(x);
    if(!find(x))g[p].push_back(x);
}


void remove(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 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;
}