Cod sursa(job #1774552)

Utilizator elffikkVasile Ermicioi elffikk Data 9 octombrie 2016 02:05:34
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.97 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <iterator>
using namespace std;

const int hsize = 45119;
vector < vector<unsigned int>  > h(hsize);

void remove(unsigned int x) {
    int i = x % hsize;
    vector<unsigned int>::iterator pos = find(h[i].begin(), h[i].end(), x);
    if(pos!=h[i].end()) {
        h[i].erase(pos);
    }
}

void put(unsigned int x) {
    int i = x % hsize;
    h[i].push_back(x);
}

bool get(unsigned int x) {
    int i = x % hsize;
    vector<unsigned int>::iterator pos = find(h[i].begin(), h[i].end(), x);
    return pos != 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";
        }
    }
}