Cod sursa(job #3151745)

Utilizator TeddyDinutaDinuta Eduard Stefan TeddyDinuta Data 22 septembrie 2023 18:39:31
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.93 kb
#include <bits/stdc++.h>

using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
const int mod = 666013;
vector<int> h[mod];
int n;
int op, x;

void add(int x) {
    int y = x % mod;
    for (auto it : h[y])
        if (x == it)
            return;
    h[y].push_back(x);
}

void del(int x) {
    int y = x % mod;
    for (int i = 0; i < h[y].size(); i++)
        if (h[y][i] == x) {
            swap(h[y][i], h[y][h[y].size() - 1]);
            h[y].pop_back();
            break;
        }
}

bool is(int x) {
    int y = x % mod;
    for (auto it : h[y])
        if (it == x)
            return 1;
    return 0;
}

int main()
{
    in >> n;
    for (int i = 1; i <= n; i++) {
        in >> op >> x;
        if (op == 1) {
            add(x);
        } else if (op == 2) {
            del(x);
        } else {
            out << is(x) << '\n';
        }
    }
    return 0;
}