Cod sursa(job #1771985)

Utilizator danstefanDamian Dan Stefan danstefan Data 6 octombrie 2016 12:55:54
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.81 kb
#include <fstream>
#include <vector>
#define M 666013
#define pb push_back
using namespace std;
vector <int> h[M];
vector <int> :: iterator it;
int x, ind,n,op,i;
vector <int> :: iterator Find() {
    for (it = h[ind].begin (); it != h[ind].end (); it++)
        if (*it == x) return it;

    return it;
}
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 % M;
        it = Find();
        if (op == 1)
            if (it == h[ind].end ()) h[ind].pb (x);
        if (op == 2)
            if (it != h[ind].end ()) h[ind].erase (it);
        if (op == 3)
            if (it != h[ind].end ()) printf("1\n");
            else printf("0\n");
    }
    return 0;
}