Cod sursa(job #2368728)

Utilizator RussianSmoothCriminalRodion Raskolnikov RussianSmoothCriminal Data 5 martie 2019 17:33:07
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.9 kb
#include <fstream>
#include <vector>
using namespace std;

ifstream fin ("hashuri.in");
ofstream fout ("hashuri.out");
const int P = 666013;

vector <int> h[P];

bool Search (int x)
{
    int r = x % P;
    for (auto v : h[r])
        if (v == x)
            return true;
    return false;
}

void Add (int x)
{
    int r = x % P;
    if (!Search(x))
        h[r].push_back(x);
}

void Remove(int x)
{
    int r = x % P, l;
    l = h[r].size();
    for (int i = 0; i < l; i++)
        if (h[r][i] == x)
        {
            swap(h[r][i], h[r][l - 1]);
            h[r].pop_back();
        }
}

void Solve ()
{
    int n, op, x;
    fin >> n;
    while (n--)
    {
        fin >> op >> x;
        if (op == 1) Add(x);
        if (op == 2) Remove(x);
        if (op == 3) fout << Search(x) << "\n";
    }
    fout.close();
}

int main()
{
    Solve();
    return 0;
}