Cod sursa(job #2894089)

Utilizator Petrica81Simion Petrica Petrica81 Data 27 aprilie 2022 11:58:54
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.92 kb
#include <iostream>
#include <fstream>
#include <vector>
#define nrmare 666013
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
vector<int> hashuri[nrmare];
bool cautare(int x){
    for(auto i = 0; i < hashuri[x%nrmare].size();i++) {
        if (x == hashuri[x%nrmare][i])
            return 1;
    }
    return 0;
}
void stergere(int x) {
    for (auto i = 0; i < hashuri[x % nrmare].size(); i++) {
        if (hashuri[x%nrmare][i] == x) {
            hashuri[x % nrmare].pop_back();
            break;
        }
    }
}
void adaugare(int x) {
    if (!cautare(x)) {
        hashuri[x%nrmare].push_back(x);
    }
}

int main() {
    int i;
    f>>i;
    while(i>0){
        int aux,x;
        f>>aux>>x;
        if(aux == 1){
            adaugare(x);
        }
        if(aux == 2){
            stergere(x);
        }
        if(aux == 3){
            g<<cautare(x)<<'\n';
        }
        --i;
    }
    return 0;
}