Cod sursa(job #3287803)

Utilizator SerbanCaroleSerban Carole SerbanCarole Data 19 martie 2025 13:36:37
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.9 kb
#include <fstream>
#include <ctime>
#include <chrono>
#include <random>
#include <vector>
#include <algorithm>
using namespace std;
ifstream cin("hashuri.in");
ofstream cout("hashuri.out");
mt19937 mt(time(nullptr));
const int nmax = 1e6 + 3;
vector <int> v[nmax];
int rnd[32], q, op, x;
int hsh(int x){
    return x%nmax;
}
bool is(int x){
    int y = hsh(x);
    for(auto it : v[y])
        if(it == x) return true;
    return false;
}
signed main()
{
    for(int i = 0 ; i < 32 ; ++i) rnd[i] = mt();
    cin >> q;
    while(q--){
        cin >> op >> x;
        if(op == 1)
            if(!is(x)) v[hsh(x)].push_back(x);
        if(op == 2){
            int y = hsh(x);
            if(is(x)) v[y].erase(find(v[y].begin(),v[y].end(),x));
        }
        if(op == 3){
            if(is(x)) cout << 1 << '\n';
            else cout << 0 << '\n';
        }
    }
    return 0;
}