Cod sursa(job #773667)

Utilizator BlueStrutAndrei Prahoveanu BlueStrut Data 2 august 2012 12:37:55
Problema Hashuri Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.88 kb
#include<cstdio>
#include<vector>
#define Mod 666013
using namespace std;
    vector <int> h[Mod];
    vector <int> :: iterator it;
int i, x, op, ind, n;
inline vector <int> :: iterator find_v(int x){
    for (it=h[ind].begin();it!=h[ind].end();it++)
    if (*it==x) return it;
    return it;
}
inline void insert_v(int x) {
    if (it==h[ind].end()) h[ind].push_back(x);
}
inline void erase_v(int x) {
    if (it!=h[ind].end()) h[ind].erase(it);
}
inline void print_v(int x) {
    if (it==h[ind].end()) printf("0\n"); else printf("1\n");
}
int main(){
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    scanf("%d", &n);
    for (i=1;i<=n;i++) {
        scanf("%d%d", &op, &x);
        ind=x/Mod;
        it=find_v(x);
        if (op==1) insert_v(x);
        if (op==2) erase_v(x);
        if (op==3) print_v(x);
    }
    return 0;
}