Cod sursa(job #2745786)

Utilizator almar.fetaFeta Almar almar.feta Data 26 aprilie 2021 23:51:39
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.96 kb
#include <fstream>
#include <vector>

using namespace std;

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

int n,cod,x;
int prim = 666013;
vector <int> H[666013];

int cauta(int x)
{
    int h = x % prim;
    for(int i=0; i<H[h].size(); i++)
        if(H[h][i] == x)
            return 1;
    return 0;
}

void adauga(int x)
{
    int h = x % prim;
    if(cauta(x) == 0)
        H[h].push_back(x);
}

void sterge(int x)
{
    int h = x % prim;
    for(int i=0; i<H[h].size(); i++)
        if(H[h][i] == x)
        {
            H[h][i] = H[h][H[h].size()-1];
            H[h].pop_back();
            break;
        }
}

int main()
{
    in >> n;
    for(int i=1; i<=n; i++)
    {
        in >> cod >> x;
        if(cod == 1)
            adauga(x);
        else if(cod == 2)
            sterge(x);
        else if(cod == 3)
            out << cauta(x) << "\n";
    }
    in.close();
    out.close();
    return 0;
}