Cod sursa(job #2146928)

Utilizator adiXMGemene Adrian adiXM Data 28 februarie 2018 12:35:28
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.16 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
const int nMax = 1000005;
const int mod = 100003;
struct Hash{
    vector <int> v[nMax];
    inline bool Search(int x) {
        int lst = x % mod;
        for(const auto& val : v[lst]) {
            if(val == x) {
                return true;
            }
        }
        return false;
    }
    inline void Insert(int x) {
        if(Search(x)) {
            return;
        }
        int lst = x % mod;
        v[lst].push_back(x);
    }
    inline void Del(int x) {
        int lst = x % mod;
        int len = v[lst].size();
        for(int i = 0; i < len; i++) {
            if(v[lst][i] == x) {
                v[lst][i] = v[lst][len - 1];
                v[lst].pop_back();
                return;
            }
        }
    }
};
Hash H;
int main()
{
    int n, tip, x;
    f >> n;
    for(int i = 1;  i <= n; i++) {
        f >> tip >> x;
        if(tip==1)
            H.Insert(x);
        else
            if(tip==2)
                H.Del(x);
        else
            g << H.Search(x) <<"\n";
    }
    return 0;
}