Cod sursa(job #687883)

Utilizator borsoszalanBorsos Zalan borsoszalan Data 22 februarie 2012 20:08:18
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.83 kb
#include <cstdio>
#include <vector>
#define Mod 666013

using namespace std;

vector <int> H[Mod];
vector <int>:: iterator it;
int n, x, op, ind, i;

vector <int>::iterator find_v(int x){

    for(it=H[ind].begin(); it!=H[ind].end(); it++)
      if (*it==x) return it;

    return it;
}

void insert_v(int x){

    if(it==H[ind].end()) H[ind].push_back(x);
}

void erase_v(int x){

    if(it!=H[ind].end()) H[ind].erase(it);
}

void write_v(int x){

    if(it!=H[ind].end()) printf("1\n");
    else printf("0\n");
}
int main(){

    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);

    scanf("%d\n", &n);

    for(i=1; i<=n; i++){

        scanf("%d%d\n", &op, &x);

        ind= x % Mod;
        it= find_v(x);

        if(op==1) insert_v(x);
        if(op==2) erase_v(x);
        if(op==3)  write_v(x);
    }

return 0;
}