Cod sursa(job #2918093)

Utilizator BlueLuca888Girbovan Robert Luca BlueLuca888 Data 9 august 2022 19:44:38
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.39 kb
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")

using namespace std;

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

int n, type, x;

const int MOD = 666317;
vector <pair<int, int>> map_hash[MOD];

inline int new_hash(const int x){
    return x % MOD;
}

inline void add_hash(const int x){
    int y = new_hash(x);

    bool found = false;
    for(int i=0; i < (int)map_hash[y].size(); i++)
        if(map_hash[y][i].first == x){
            map_hash[y][i].second++;
            found = true;
        }

    if(!found)
        map_hash[y].push_back({x, 1});
}

inline void remove_hash(const int x){
    int y = new_hash(x);

    for(int i=0; i < (int)map_hash[y].size(); i++)
        if(map_hash[y][i].first == x && map_hash[y][i].second)
            map_hash[y][i].second--;
}

inline bool query_hash(const int x){
    int y = new_hash(x);
    for(int i=0; i < (int)map_hash[y].size(); i++)
        if(map_hash[y][i].first == x && map_hash[y][i].second)
            return true;
    return false;
}

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

    fin>>n;
    while(n--){
        fin>>type>>x;
        if(type == 1){
            add_hash(x);
        }else if(type == 2){
            remove_hash(x);
        }else{
            fout<<query_hash(x)<<"\n";
        }
    }
    return 0;
}