Cod sursa(job #2376812)

Utilizator Bulboaca_EugenBulboaca Alexandru Eugen Bulboaca_Eugen Data 8 martie 2019 17:52:04
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.93 kb
#include <bits/stdc++.h>
using namespace std;
const int MAXN =1e6  + 40;
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) swap(a, hashh[modulo].back()), hashh[modulo].pop_back();
    }
}
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;

}