Cod sursa(job #2253256)

Utilizator pinteastefanPintea Teodor Stefan pinteastefan Data 3 octombrie 2018 20:16:11
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.87 kb
#include <bits/stdc++.h>

using namespace std;
const int MOD = 666013;
vector <int> v[MOD];

bool find (int x)
{
    int where = x % MOD;
    for (auto &y : v [where])
        if (x == y) return true;
    return false;
}
void insert (int x)
{
    if (find (x))
        return;
    v[x % MOD].push_back(x);
}
void erase (int x)
{
    if (!find (x))
        return;
    int where = x % MOD;
    for (int i = 0; i < (int)v[where].size(); ++ i)
    {
        int &y = v [where][i];
        if (y == x)
        {
            swap (v [where].back(), v[where][i]);
            v[where].pop_back();
        }
    }
}
int main() {
    ifstream f("hashuri.in");
    ofstream g("hashuri.out");
    int n, x, op;
    f >> n;
    for (int i = 1; i <= n; i++) {
        f >> op >> x;
        if (op == 1) insert(x);
        else if (op == 2) erase(x);
        else g << find (x) << '\n';
    }
    return 0;
}