Cod sursa(job #1970138)

Utilizator andreigasparoviciAndrei Gasparovici andreigasparovici Data 18 aprilie 2017 22:15:00
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.54 kb
#include <bits/stdc++.h>
using namespace std;

const int SIZE = 100000;

class InParser {
    char buffer[SIZE];
    int pos;
    char next_char(){
        if(pos == SIZE){
            pos = 0;
            fread(buffer, 1, SIZE, stdin);
        }
        return buffer[pos++];
    }
public:
    InParser(){
        pos = 0;
        fread(buffer, 1, SIZE, stdin);
    }
    InParser& operator>>(int &x){
        x = 0;    
        char c = next_char();
        while(c < '0' || c > '9'){
            c = next_char();
        }
        while(c >= '0' && c <='9'){
            x = x * 10 + c - '0';
            c = next_char();
        }

        return *this;
    }
};
 
const int MAXN = 1000001;
const int MOD = 666013;
 
vector<int> h[MOD];
 
bool hash_find(int nod){
    int where = nod % MOD;
    return find(h[where].begin(), h[where].end(), nod) != h[where].end();
}
 
void hash_insert(int nod){
    int where = nod % MOD;
    if(!hash_find(nod)){
        h[where].push_back(nod);
    }
}
 
void hash_remove(int nod){
    int where = nod % MOD;
    auto it = find(h[where].begin(), h[where].end(), nod);
    if(it == h[where].end())
        return;
    h[where].erase(it);
}
 
int q;
 
int main(){
    freopen("hashuri.in", "r", stdin);
    freopen("hashuri.out", "w", stdout);

    InParser in;

    in>>q;
    while(q--){
        int op,  param;
        in>>op>>param;
        if(op == 1){
            hash_insert(param);   
        } else if(op == 2){
            hash_remove(param);
        } else {
           printf("%d\n", hash_find(param)); 
        }
    }
}