Cod sursa(job #1650188)

Utilizator Vali_DeaconuVali Deaconu Vali_Deaconu Data 11 martie 2016 17:05:07
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.88 kb
# include <fstream>
# include <vector>

# define foreach(A) for(typeof (A).begin() it = (A).begin(); it != (A).end(); ++it)

using namespace std;

ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

const int MOD = 666013;
vector<int> h[MOD];

bool Verifica(int x) {
    int key = x % MOD;
    foreach(h[key])
        if (*it == x)
            return 1;
    return 0;
}

void Adauga(int x) {
    if (!Verifica(x)) {
        int key = x % MOD;
        h[key].push_back(x);
    }
}

void Sterge(int x) {
    int key = x % MOD;
    foreach (h[key])
        if (*it == x) {
            h[key].erase(it);
            break;
        }
}

int N, t, x;
int main() {
    fin >> N;
    while (N--) {
        fin >> t >> x;
        if (t == 1) Adauga(x);
        if (t == 2) Sterge(x);
        if (t == 3) fout << Verifica(x) << "\n";
    }
    return 0;
}