Cod sursa(job #2743167)

Utilizator bianca_voicuBianca Voicu bianca_voicu Data 22 aprilie 2021 17:29:00
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.91 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;
ifstream f("hashuri.in");
ofstream o("hashuri.out");

const int prim = 666013;

vector<int> v[prim];

int exists(int x) {
    int i, h = x % prim;
    for (i = 0; i < v[h].size(); i++)
        if (v[h][i] == x)
            return 1;
    return 0;
}

void add(int x) {
    int h = x % prim;
    if (exists(x) == 0)
        v[h].push_back(x);
}

void del(int x) {
    int i, h = x % prim;;
    for (i = 0; i < v[h].size(); i++)
        if (v[h][i] == x) {
            v[h].erase(v[h].begin() + i);
            break;
        }
}


int main() {
    int n, i, x, op;
    f >> n;
    for (i = 0; i < n; i++) {
        f >> op >> x;
        if (op == 1)
            add(x);
        else if (op == 2)
            del(x);
        else o << exists(x) << "\n";

    }

    f.close();
    o.close();
    return 0;
}