Cod sursa(job #2895178)

Utilizator cosminnnnnnnaDuca Cosmina cosminnnnnnna Data 28 aprilie 2022 19:57:16
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.96 kb
#include <iostream>
#include <fstream>
#include <vector>
#define val  666013

using namespace std;


ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

vector <int> M[val+1];

int verificare(int x){
    int l = x % val;

    for  (auto && pos = M[l].begin(); pos != M[l].end(); pos++)
        if(*pos == x)
            return 1;
    return 0;
}


void inserare (int x){
    int l = x % val;
    if (verificare(x) == 0)
        M[l].push_back(x);

}

void stergere(int x){
    int l  = x % val;

    for (auto && pos = M[l].begin(); pos != M[l].end(); pos++)
        if (*pos == x) {
            M[l].erase(pos);
            break;
        }
}


int main() {
    int N, operatie, parametru;
    fin >> N;
    for (int i = 0; i < N; i++) {
        fin >> operatie >> parametru;
        if (operatie == 1)
            inserare(parametru);
        else if (operatie == 2)
            stergere(parametru);
        else fout << verificare(parametru) << endl;

    }
    return 0;
}