Cod sursa(job #1774532)

Utilizator elffikkVasile Ermicioi elffikk Data 9 octombrie 2016 01:20:55
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb
#include <iostream>
#include <fstream>
#include <map>
#include <vector>
using namespace std;

const int hsize = 100000;
vector < map<unsigned int, bool>  > h(hsize);

void remove(unsigned int x) {
    int i = x / hsize;
    if(h[i].find(x)!=h[i].end()) {
        h[i].erase(h[i].find(x));
    }
}

void put(unsigned int x) {
    int i = x / hsize;
    h[i][x] = true;
}

bool get(unsigned int x) {
    int i = x / hsize;
    return h[i].find(x) != h[i].end();
}

int main() {
    ifstream cin("hashuri.in");
    ofstream cout("hashuri.out");
    unsigned int n, op, x;
    cin>>n;
    for (int i = 0; i < n; i++) {
        cin>>op>>x;
        if (op == 1) {
            put(x);
        } else if (op == 2) {
            remove(x);
        } else {
            cout<<get(x)<<"\n";
        }
    }
}