Cod sursa(job #2733445)

Utilizator StarkillerCalin Stafie Starkiller Data 30 martie 2021 14:51:09
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.35 kb
#include <bits/stdc++.h>
#define MOD 666013

using namespace std;
ifstream fin("hashuri.in");
ofstream gout("hashuri.out");

int n, x, op;
vector <int> hash_table[666013];

void inserare (vector <int> v[], int x)
{
    int poz = x % MOD;
    if (find(v[poz].begin(), v[poz].end(), x) == v[poz].end())
        v[poz].push_back(x);
}
void stergere (vector <int> v[], int x)
{
    int poz = x % MOD;
    if (find(v[poz].begin(), v[poz].end(), x) != v[poz].end())
    {
        vector <int>::iterator it;
        it = find(v[poz].begin(), v[poz].end(), x);
        int gasit = it - v[poz].begin();
        v[poz].erase(v[poz].begin() + gasit);
    }
}
bool cautare (vector <int> v[], int x)
{
    int poz = x % MOD;
    if (find(v[poz].begin(), v[poz].end(), x) == v[poz].end())
        return 0;
    return 1;
}

int main()
{
    fin >> n;
    for(int t = 0 ; t < n ; ++t)
    {
        fin >> op;
        fin >> x;
        switch (op)
        {
        case 1:
            {
                inserare(hash_table, x);
                break;
            }

        case 2:
            {
                stergere(hash_table, x);
                break;
            }
        case 3:
            {
                gout << cautare(hash_table, x) << "\n";
                break;
            }
        }
    }


    return 0;
}