Cod sursa(job #719162)

Utilizator SpiderManSimoiu Robert SpiderMan Data 21 martie 2012 15:24:11
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.99 kb
# include <algorithm>
# include <cassert>
# include <cstdio>
# include <vector>
using namespace std;

const char *FIN = "hashuri.in", *FOU = "hashuri.out";
const int MOD = 666013;

int T, tip, nr;
vector <int> G[MOD];

inline vector <int> :: iterator search (int val) {
    int nr = val % MOD;
    return find (G[nr].begin (), G[nr].end (), val);
}

inline void insert (int val) {
    int nr = val % MOD;
    if (search (val) == G[nr].end ()) G[nr].push_back (val);
}

inline void erase (int val) {
    int nr = val % MOD;
    vector <int> :: iterator aux = search (val);
    if (aux != G[nr].end ()) G[nr].erase (aux);
}

int main (void) {
    assert (freopen (FIN, "r", stdin));
    assert (freopen (FOU, "w", stdout));

    for (assert (scanf ("%d", &T) == 1); T; --T) {
        assert (scanf ("%d %d", &tip, &nr) == 2);
        if (tip == 1) insert (nr);
        if (tip == 2) erase (nr);
        if (tip == 3) printf ("%d\n", search (nr) != G[nr % MOD].end ());
    }
}