Cod sursa(job #2743536)

Utilizator PopelEmilBogdanPopel Emil-Bogdan PopelEmilBogdan Data 23 aprilie 2021 10:29:31
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.2 kb
#include<vector>
#include<fstream>

using namespace std;

#define HASH 999983


ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int N;
vector<int> LISTE[HASH]; // array of 999983 vectors

inline vector<int>::iterator Find(int x)
{
    int hashPos = x % HASH;
    vector<int>::iterator it;

    for(it = LISTE[hashPos].begin(); it!= LISTE[hashPos].end(); it++)
        if(*it == x)
            return it;

    return LISTE[hashPos].end();
}

inline void Insert(int x)
{
    int hashPos = x % HASH;
    if(Find(x) == LISTE[hashPos].end())
        LISTE[hashPos].push_back(x);
}

inline void Erase(int x)
{
    int hashPos = x % HASH;
    vector<int>::iterator it;
    it = Find(x);

    if(it!= LISTE[hashPos].end())
        LISTE[hashPos].erase(it);
}
int main()
{
    int n, op, x;
    fin>>n;
    for(int i = 0; i< n; i++)
    {
        fin>>op>>x;

        if(op == 1)  {Insert(x); continue;}
        if(op == 2) {Erase(x);continue;}
        if(op==3)
            {
            if(Find(x) != LISTE[x%HASH].end())
                {fout<<1<<"\n";continue;}
            else
                {fout<<0<<"\n";continue;}
            }
    }
    return 0;

}