Cod sursa(job #3130137)

Utilizator adelibdAdel Ib adelibd Data 16 mai 2023 22:11:30
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.4 kb
#include <iostream>
#include <fstream>
#include <queue>
#include <algorithm>
int n, tipOp, x;

//std::ifstream fin("C:\\Users\\DelMX\\OneDrive\\Sharing\\tema-sd-3\\hashuri.in");
//std::ofstream fout("C:\\Users\\DelMX\\OneDrive\\Sharing\\tema-sd-3\\hashuri.out");
std::ifstream fin("hashuri.in");
std::ofstream fout("hashuri.out");

int bigN = 666666;
std::vector<int> v[666666];

bool cautare(int x) {
    int cheie = x % bigN;
    for (int i = 0; i < v[cheie].size(); ++i) {
        if (v[cheie][i] == x)
            return 1;
    }
    return 0;
}

int main() {

    fin >> n;
    for (int i = 0; i < n; ++i) {
        fin >> tipOp >> x;
        int cheie = x % bigN;
        switch(tipOp) {
            case 1: {
                if (!cautare(x)); {
                    v[cheie].push_back(x);
                }
                break;
            }
            case 2: {
                for (int i = 0; i < v[cheie].size(); ++i) {
                    if (v[cheie][i] == x) {
                        for (int j = i; j < v[cheie].size(); ++j) {
                            v[cheie][j] = v[cheie][j + 1];
                        }
                        v[cheie].pop_back();
                    }
                }
                break;
            }
            case 3: {
//                std::cout << cautare(x) << "\n";
                fout << cautare(x) << "\n";
                break;
            }
        }
    }

    return 0;
}