Cod sursa(job #2129722)

Utilizator mihnea00Duican Mihnea mihnea00 Data 13 februarie 2018 00:52:58
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.15 kb
#include <fstream>

using namespace std;

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

int n,m,caz,i,idx,j,x,prim=666013,tabrest[666020];
struct elemente
{
    int valoare,inapoila;
} v[1000010];

int srch(int x)
{
    int rest=x%prim;
    int poz=tabrest[rest];

    while(poz)
    {
        if(x==v[poz].valoare)
            return poz;
        poz=v[poz].inapoila;
    }
    return 0;
}

void pune(int x)
{
    int rest=x%prim;
    if(srch(x)!=0)
        return;
    ++idx;
    v[idx].valoare=x;
    v[idx].inapoila=tabrest[rest];
    tabrest[rest]=idx;
}

void sterge(int x)
{
    int rest=x%prim;
    int poz=srch(x);
    if(poz==0)
        return;
    v[poz].valoare=-1;
}

int main()
{
    fin>>n;
    for(i=1;i<=n;++i)
    {
        fin>>caz>>x;
        if(caz==1)
            pune(x);
        else
            if(caz==2)
                sterge(x);
            else
                if(caz==3)
                {
                    if(srch(x))
                        fout<<1<<"\n";
                    else
                        fout<<0<<"\n";
                }
    }
    return 0;
}