Cod sursa(job #2623709)

Utilizator TaveNeagoe Gabriel-Octavian Tave Data 3 iunie 2020 16:59:57
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.05 kb
#include <fstream>
#include <vector>
using namespace std;

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

const unsigned P = 66923;
vector<unsigned int> M[P];

unsigned int H(long long x) //functia de hash
{
    return x%P;
}

bool isIn(long long x)
{
    bool res=false;
    unsigned int pos = H(x);
    for (int i=0; i<M[pos].size(); i++)
        if(M[pos][i]==x)
        res = true;
    return res;
}

void del(long long x) //functie dedicata de stergere pentru a nu apela isIn degeaba
{
    unsigned int pos = H(x);
    for (int i=0; i<M[pos].size(); i++)
        if(M[pos][i]==x)
        {M[pos].erase(M[pos].begin()+i); break;}
}

int main()
{

    long long N, i, x;
    int op;
    fin>>N;
    for (i=0; i<N; i++)
    {
        fin>>op>>x;

        if(op==1)
        {
            if(!isIn(x))
            M[H(x)].push_back(x);
        }
        else if(op==2)
        {
            del(x);
        }
        else
        {
            fout<<isIn(x)<<'\n';
        }
    }


    return 0;
}