Cod sursa(job #2702687)

Utilizator DragosC1Dragos DragosC1 Data 5 februarie 2021 15:11:13
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.01 kb
#include <fstream>
#include <vector>
using namespace std;

const int MOD = 914239;

int n;
vector<int> a[MOD];

vector<int>::iterator find(int x) {
    vector<int>::iterator it;
    int lista = x % MOD;
    for (it = a[lista].begin(); it < a[lista].end(); it++)
        if (*it == x)
            return it;
    return a[lista].end();
}

void adauga(int x) {
    int lista = x % MOD;
    if (find(x) == a[lista].end())
        a[lista].emplace_back(x);
}

void sterge(int x) {
    int lista = x % MOD;
    vector<int>::iterator it;
    it = find(x);
    if (it != a[lista].end())
        a[lista].erase(it);
}

int main() {
    int i, x, op;
    ifstream f("hashuri.in");
    ofstream g("hashuri.out");
    f >> n;
    for (i = 1; i <= n; i++) {
        f >> op >> x;
        if (op == 1) 
            adauga(x);
        else if (op == 2) 
            sterge(x);
        else 
            g << (find(x) != a[x % MOD].end()) << '\n';
    }
    f.close();
    g.close();
    return 0;
}