Cod sursa(job #2834319)

Utilizator rusenmihai101@gmail.comMihai Rusen [email protected] Data 16 ianuarie 2022 20:37:57
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.99 kb
#include <fstream>
#include <vector>
using namespace std;

const int MOD = 12289;
vector < int > H[MOD];

inline static void Add(int value){
    int key = value % MOD;
    for(auto x: H[key])
        if(x == value)
            return ;
    H[key].push_back(value);
}

inline static void Erase(int value){
    int key = value % MOD;
    int len = (int) H[key].size();
    for(int i = 0; i < len; ++i)
        if(value == H[key][i]){
            H[key][i] = H[key][len - 1];
            H[key].pop_back();
            return ;
        }
}

inline bool Find(int value){
    int key = value % MOD;
    for(auto x: H[key])
        if(x == value)
            return true;
    return false;
}

int main(){

    ifstream cin("hashuri.in");
    ofstream cout("hashuri.out");
    int Queries, op, x;
    cin >> Queries;
    while(Queries--){
        cin >> op >> x;
        if(op == 1)
            Add(x);
        else if(op == 2)
            Erase(x);
        else
            cout << Find(x) << '\n';
    }

    return 0;
}