Cod sursa(job #2418986)

Utilizator EricEric Vilcu Eric Data 7 mai 2019 11:43:51
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.92 kb
#include <iostream>
#include <fstream>
#define bpr 666019
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int n,x,xm,q;
struct vct{int v;vct*n;}*a[bpr],*k,*kf;
bool ex(int xm,int x)
{
    for(k=kf=a[xm];kf!=NULL;k=kf,kf=kf->n)if(kf->v==x)return 1;
    return 0;
}
int main()
{
    for(f>>n;n>0;--n)
    {
        f>>q>>x;
        xm=x%bpr;
        switch(q)
        {
            case 1:
            if(!ex(xm,x))
            {
                k=new vct;
                k->v=x;
                k->n=a[xm];
                a[xm]=k;
            }
            break;
            case 2:
            if(ex(xm,x)){
                if(k->v==kf->v){a[xm]=a[xm]->n;delete(kf);}
                else {k->n=kf->n;delete(kf);}
            }
            break;
            case 3:
            if(!ex(xm,x))g<<"0\n";
            else g<<"1\n";
            break;
        }
    }
}