Cod sursa(job #2376795)

Utilizator Bulboaca_EugenBulboaca Alexandru Eugen Bulboaca_Eugen Data 8 martie 2019 17:44:20
Problema Hashuri Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.92 kb
#include <bits/stdc++.h>
using namespace std;
const int MAXN =1e6  + 20;
const int MOD = 999917;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
vector <int> hashh[MAXN];
void insertt(int x){
    int modulo = x % MOD;
    hashh[modulo].push_back(x);
}
void erasee(int x){
    int modulo = x % MOD, cnt = 0;
    for(auto a : hashh[modulo]){
        cnt++;
        if(a == x) hashh[modulo].erase(hashh[modulo].begin() + cnt - 1);
    }
}
bool findd(int x){
    int modulo = x % MOD;
    for(auto a : hashh[modulo]){
        if(a == x) return true;
    }
    return false;
}
///hashuri
///cabana
int main(){

    ios::sync_with_stdio(false);
    fin.tie(0);fout.tie(0);
    int n, type, x;
    fin >> n;
    for(int i = 1; i <= n; ++i){
        fin >> type >> x;
        if(type == 1) insertt(x);
        else if(type == 2) erasee(x);
        else fout << findd(x) << '\n';
    }
    return 0;

}