Cod sursa(job #2866734)

Utilizator tomaionutIDorando tomaionut Data 9 martie 2022 22:07:47
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.87 kb
#include <bits/stdc++.h>
#define p 123457
using namespace std;

ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int q, op, x;
vector <int> h[p];
void Add(int x)
{
    int r = x % p;
    for (auto w : h[r])
        if (w == x) return;
    h[r].push_back(x);
}

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

bool Find(int x)
{
    int r = x % p;
    for (auto w : h[r])
        if (w == x) return 1;
    return 0;
}

int main()
{
    fin >> q;
    while (q--)
    {
        fin >> op >> x;
        if (op == 1)
            Add(x);
        else if (op == 2)
            Delete(x);
        else 
            fout << Find(x) << "\n";
    }

    return 0;
}