Cod sursa(job #1788093)

Utilizator bciobanuBogdan Ciobanu bciobanu Data 25 octombrie 2016 17:39:02
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    ifstream cin("hashuri.in");
    ofstream cout("hashuri.out");
    cin.tie(0);
    ios_base::sync_with_stdio(false);
 
    int n; cin >> n;
     
    unordered_set<int> hash_set;
    hash_set.reserve(n);
    hash_set.max_load_factor(.5);

    srand(time(0));
    const int xor_const = (rand() << 15) ^ rand();
 
    for (int iter = 0; iter < n; iter += 1) {
        int op_type, el; cin >> op_type >> el; 
        el ^= xor_const;
 
        if (op_type == 1) {
            hash_set.insert(el);
        } else if (op_type == 2) {
            hash_set.erase(el);
        } else {
            cout << (hash_set.find(el) != hash_set.end()) << '\n';
        }
    }
 
    return