Cod sursa(job #2746917)

Utilizator truscalucaLuca Trusca truscaluca Data 28 aprilie 2021 18:02:26
Problema Hashuri Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.94 kb
#include <iostream>

using namespace std;

const int nMax = 1000005;

int v[nMax], vSize, q, cod, x;

int main() {
    freopen("hashuri.in", "r", stdin);
    freopen("hashuri.out", "w", stdout);

    // Input rapid
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> cod >> x;
        if (cod == 1) {
            v[vSize++] = x;
        } else if (cod == 2) {
            for (int j = 0; j < vSize; j++) {
                if (v[j] == x) {
                    v[j] = v[vSize - 1];
                    vSize--;
                }
            }
        } else if (cod == 3) {
            int found = 0;
            for (int j = 0; j < vSize && !found; j++) {
                if (v[j] == x) {
                    cout << "1\n";
                    found = 1;
                }
            }
            if (!found) {
                cout << "0\n";
            }
        }
    }
    return 0;
}