Cod sursa(job #2774803)

Utilizator andrei_C1Andrei Chertes andrei_C1 Data 12 septembrie 2021 21:04:35
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.93 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
const int MOD = 769553;
vector<vector<int>>h(MOD);
int Q;
void push(int val) {
    int h_val = val % MOD;
    for(auto it: h[h_val]) {
        if(it == val) {
            return;
        }
    }
    h[h_val].push_back(val);
}
void pop(int val) {
    int h_val = val % MOD;
    auto it = find(h[h_val].begin(), h[h_val].end(), val);
    if(it != h[h_val].end()) {
        h[h_val].erase(it);
    }
}
bool check(int val) {
    int h_val = val % MOD;
    auto it = find(h[h_val].begin(), h[h_val].end(), val);
    return (it != h[h_val].end());
}
int main() {
    for(fin >> Q; Q--; ) {
        int op, x;
        fin >> op >> x;
        if(op == 1) {
            push(x);
        } else if(op == 2) {
            pop(x);
        } else {
            fout << check(x) << '\n';
        }
    }
    return 0;
}