Cod sursa(job #3149107)

Utilizator BlueLuca888Girbovan Robert Luca BlueLuca888 Data 6 septembrie 2023 14:19:34
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.4 kb
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#pragma GCC target ("popcnt")

using namespace std;

ifstream fin  ("hashuri.in");
ofstream fout ("hashuri.out");

const int MAX_N = 1'000'000;
const int LIM = 2'000'000'000;
const int MOD = 7919;

int n, t, x;

int xhash;
bool found;
vector<pair<int, bool>> h[MOD];

static inline void add(){
    xhash = x % MOD;
    found = false;

    for(auto p : h[xhash]){
        if(p.first == x){
            found = true;
            p.second = true;
            break;
        }
    }
    if(!found)
        h[xhash].push_back({x, true});
}

static inline void rem(){
    xhash = x % MOD;

    for(auto &p : h[xhash]){
        if(p.first == x){
            p.second = false;
            break;
        }
    }
}

static inline bool query(){
    xhash = x % MOD;
    found = false;

    for(auto p : h[xhash]){
        if(p.first == x){
            if(p.second == true)
                found = true;
            break;
        }
    }

    return found;
}

int main (){
    ios_base::sync_with_stdio(false);
    fin.tie(nullptr), fout.tie(nullptr);

    fin>>n;
    while(n--){
        fin>>t>>x;
        if(t == 1){ ///update add
            add();

        }else if(t == 2){ ///update remove
            rem();

        }else{ ///query
            fout<<query()<<"\n";
        }
    }
    return 0;
}