Cod sursa(job #2774799)

Utilizator andrei_C1Andrei Chertes andrei_C1 Data 12 septembrie 2021 20:40:26
Problema Hashuri Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.85 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
const int mask = (1 << 14) - 1;
vector<vector<int>>h(mask);
int Q;
void push(int val) {
    int h_val = val & mask;
    h[h_val].push_back(val);
}
void pop(int val) {
    int h_val = val & mask;
    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 & mask;
    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;
}