Cod sursa(job #2116987)

Utilizator razvan242Zoltan Razvan-Daniel razvan242 Data 28 ianuarie 2018 13:19:02
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.25 kb
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

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

const int MOD = 666013; // cheia comuna pentru anumite numere e VAL % MOD

vector <int> v[MOD]; // v[i] cu i = 0, MOD - 1 este VID ACUM!

inline void insertValue(int val) {
    int key = val % MOD;

    if (find(v[key].begin(), v[key].end(), val) == v[key].end()) {
        // NU L-AM GASIT PE val IN v[key]
        v[key].push_back(val);
    }
}

inline void deleteValue(int val) {
    int key = val % MOD;

    vector <int>::iterator it = find(v[key].begin(), v[key].end(), val);
    if (it != v[key].end()) {
        // l-am gasit pe val in v[key]
        v[key].erase(it);
    }
}

inline int findValue(int val) {
    int key = val % MOD;

    vector <int>::iterator it = find(v[key].begin(), v[key].end(), val);
    return it != v[key].end();
}

int main()
{
    int n;
    fin >> n;
    int op, val;
    while (n--) {
        fin >> op >> val;
        if (op == 1) { // insert
            insertValue(val);
        }
        else if (op == 2) {
            deleteValue(val);
        }
        else {
            fout << findValue(val) << '\n';
        }
    }
    return 0;
}