Cod sursa(job #2617715)

Utilizator DiagrDiana Grigore Diagr Data 22 mai 2020 17:46:59
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.15 kb
#include <bits/stdc++.h>
using namespace std;
vector<int> v[666013];
int n;
vector<int> :: iterator gaseste(int x){
    int pozitie = x % 666013;
    for (vector<int> :: iterator it = v[pozitie].begin(); it != v[pozitie].end(); it++)
            if (*it == x)
                return it;
    return v[pozitie].end();
}

void insereaza(int x){
    int pozitie = x % 666013;
    if(gaseste(x) == v[pozitie].end())
        v[pozitie].push_back(x);
}

void sterge(int x){
    int pozitie = x % 666013;
    if (gaseste(x) != v[pozitie].end())
        v[pozitie].erase(gaseste(x));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    freopen("hashuri.in", "r", stdin);
    freopen("hashuri.out", "w", stdout);
    cin >> n;
    for (int i = 0; i < n; i++){
        int op, x;
        cin >> op >> x;
        if (op == 1)
            insereaza(x);
        else {
            if (op == 2)
                sterge(x);
            else
                if (gaseste(x) != v[x % 666013].end())
                    cout << "1" << '\n';
                else
                    cout << "0" << '\n';
        }
    }
    return 0;
}