Guest User

Untitled

a guest
Oct 19th, 2020
59
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<map>
  2. #define A;return
  3. #define N new E{
  4. using S=std::string;using C=char;using I=int;S V(I i){A(i>8?V(i/9):"")+C(97+i%9);}S W(C*&s){C*b=s;while(*++s>96)A{b,s};}struct E{I t,i;E*l,*r;E(E&o,I d,I e){t=o.t;i=o.i+(o.i>=d)*e;t?l=N*o.l,d,e},t-1?r=N*o.r,d,e}:0:0;}E(I d,std::map<S,I>m,C*&s){t=*s-40?i=m[W(s)],0:*++s-92?l=N d,m,s},r=N d,m,++s},++s,2:(m[W(s+=2)]=d,l=N-~d,m,s+=2},++s,1);}I R(I d){A t?t-1?l->t==1?l->l->s(d,0,*r),*this=*l->l,1:l->R(d)||r->R(d):l->R(d+1):0;}I s(I d,I e,E&v){t?t-1?l->s(d,e,v),r->s(d,e,v):l->s(d,e+1,v):i==d?*this={v,d,e},0:i-=i>d;}S u(I d){A t?t-1?"("+l->u(d)+' '+r->u(d)+')':"(\\ "+V(d)+". "+l->u(d+1)+')':V(i);}};S f(C*s){E a{0,{},s};for(I c=999;a.R(0)&&c--;)A a.u(0);}
RAW Paste Data