Cod sursa(job #2421106)

Utilizator BlaugranasEnal Gemaledin Blaugranas Data 14 mai 2019 12:17:50
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.83 kb
#include<cstdio>
#define M 666013
#define P 15000000
typedef struct O
{
    int I;
    O *U;
}N;
int n,y,x,z,e=-1,l;
N *h[M],*p,*q;
char r[P];
inline int A()
{
  	int s=0;
  	for(e++;r[e]>47;e++)
  		s=s*10+r[e]-48;
  	return s;
}
inline void S(int x)
{
    int i,d=x>999999999?10:x>99999999?9:x>9999999?8:x>999999?7:x>99999?6:x>9999?5:x>999?4:x>99?3:x>9?2:1;
    for(i=d-1;i>=0;x/=10,i--)
        r[l+i]=x%10+48;
    r[l+d]=10,l+=d+1;
}
int main()
{
    freopen("hashuri.in","r",stdin),freopen("hashuri.out","w",stdout),fread(r,1,P,stdin),n=A();
    while(n--)
	{
        for(x=A(),y=A(),z=y%M,p=q=h[z];p&&p->I!=y;q=p,p=p->U);
        if(x==1&&!p)
            p=new N,p->U=h[z],p->I=y,h[z]=p;
        else if(x==2&&p)
            q==p?h[z]=h[z]->U:q->U=p->U;
        else if(x==3)
            S(p?1:0);
    }
    fwrite(r,1,l,stdout);
}