Cod sursa(job #2450125)

Utilizator ejoi2019Ejoi 2019 ejoi2019 Data 21 august 2019 23:40:10
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.53 kb
#include <iostream>
#include <cstdio>

using namespace std;

const int N=1000007;
int n;

struct node
{
        int store;
        node *urm;
        node()
        {
                store=-1;
                urm=0;
        }
};

const int M=(1<<20)+(int)1e4;
node *kol[M];

bool is(node *now,int x)
{
      //  cout<<" : "<<(now->urm==0)<<"\n";
        if(now->store==x)
                return 1;
        if(now->urm==0)
                return 0;
        return is(now->urm,x);
}

void baga(node *now,int x)
{
        if(now->store==x)
                return;
        if(now->urm==0)
        {
                now->urm=new node;
                now->urm->store=x;
                return;
        }
        baga(now->urm,x);
}

node *last;

void sterge(node *now,int x)
{
        if(now->store==x)
        {
                last->urm=now->urm;
                delete now;
                return;
        }
        if(now->urm==0)
                return;
        last=now;
        sterge(now->urm,x);
}

int main()
{
        freopen("hashuri.in","r",stdin);
        freopen("hashuri.out","w",stdout);
        for(int i=0;i<M;i++)
                kol[i]=new node;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
                int t,x;
                scanf("%d%d",&t,&x);
                int h=x%(1<<20);
                if(t==1) baga(kol[h],x);
                if(t==2) sterge(kol[h],x);
                if(t==3) printf("%d\n",is(kol[h],x));
        }

        return 0;
}