Cod sursa(job #2536249)

Utilizator halexandru11Hritcan Alexandru halexandru11 Data 1 februarie 2020 17:53:22
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.1 kb
#include <bits/stdc++.h>

#define mod 666013
#define nax (1e6 + 3)
#define pb push_back

using namespace std;

ifstream f("hashuri.in");
ofstream g("hashuri.out");

vector<int> mat[mod];
int n;

int Hashing(const int& x)
{
    return x % mod;
}

bool Exista(const int& x)
{
    int row = Hashing(x);
    for(auto& it : mat[row])
        if(it == x)
            return true;
    return false;
}

void Adauga(const int& x)
{
    if(!Exista(x))
    {
        int row = Hashing(x);
        mat[row].pb(x);
    }
}

void Elimina(const int& x)
{
    int row = Hashing(x);
    for(size_t i = 0; i < mat[row].size(); ++i)
        if(mat[row][i] == x)
        {
            mat[row].erase(mat[row].begin() + i);
            return;
        }
}

void Read()
{
    int i = 1, c, x;
    f >> n;
    for(; i <= n; ++i)
    {
        f >> c >> x;
        if(c == 1)
            Adauga(x);
        else if(c == 2)
            Elimina(x);
        else
            g << Exista(x) << "\n";
    }
}

int main()
{
    ios::sync_with_stdio(false);
    Read();
    return 0;
}