Cod sursa(job #2746443)

Utilizator SebicaPGLSebastian Ionel SebicaPGL Data 27 aprilie 2021 21:23:31
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.21 kb
#include <bits/stdc++.h>
#include <iostream>
using namespace std;


int n;
vector<int> hashMap[666013];

inline vector<int>::iterator findVal(int x)
{
    int lista = x % 666013;
    vector<int>::iterator it;

    for(it = hashMap[lista].begin(); it != hashMap[lista].end(); it++){
        if(*it == x) {
            return it;
        }
    }
    return hashMap[lista].end();
}

inline void insertVal(int x)
{
    int lista = x % 666013;
    if(findVal(x) == hashMap[lista].end()){
        hashMap[lista].push_back(x);
    }
}

inline void eraseVal(int x)
{
    int lista = x % 666013;
    vector<int>::iterator it = findVal(x);
    if(it != hashMap[lista].end()){
        hashMap[lista].erase(it);
    }

}
int main()
{
    int op, x;
    // jur ca ma las de facultate
    ifstream f("hashuri.in");
    ofstream o("hashuri.out");
    f >> n;
    for(int i = 0; i < n; i++){
        f >> op >> x;

        if(op == 1){
            insertVal(x);
            continue;
        }
        if(op == 2){
            eraseVal(x);
            continue;
        }
        if(op == 3){
            o << (findVal(x) != hashMap[x % 666013].end()) << "\n";
        }
    }
    return 0;
}