You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

54 lines
4.0 KiB

#include"a.h" // ngn/k, (c) 2019-2021 ngn, GNU AGPLv3 - https://codeberg.org/ngn/k/raw/branch/master/LICENSE
#define c_(T,R,p) SN V c##T##R(OV*RE v,V*RE w,Nn)_(O T*RE a=v;R*RE r=w;i(PD(n,p),r[i]=a[i]))
#define cN(T,R,p) SN V c##T##R(OV*RE v,V*RE w,Nn)_(O T*RE a=v;R*RE r=w;i(PD(n,p),r[i]=a[i]==N##T?N##R:a[i]))
c_(B,H,r)c_(H,B,a)c_(B,I,r)c_(I,B,a)c_(L,B,a)c_(H,I,r)c_(I,H,a)c_(H,L,r)c_(L,H,a)c_(I,L,r)c_(L,I,a)cN(L,D,a)cN(D,L,a)
A1(flp,XM(Ay=kv(&x);am(x,y))
Xm(Ay=kv(&x);I(ytT>ytA,y=flp(flp(y)))P(!ytA,et2(x,y))Ln=cfm(yA,yn);P(n<0,el2(x,y))i(yn,Az=ya;I(ztt,y=mut(y);ya=rsh(n,z)))aM(x,y))
Xt(enl(enl(x)))P(!xtA||!xn,enl(x))Ln=cfm(xA,xn);P(n==-1,enl(x))P(n<0,el1(x))
Ct=_t(*xA);I(t<tM,i(xn,Ay=xa;B(yt-t,t=0)))E(t=0)Ay=aA(n);P(!t,i(n,Az=aA(xn);j(xn,zA[j]=ii(xA[j],i))ya=sqz(z))x(y))
I w=Tz[t];i(n,Az=ya=an(t,xn);j(xn,Ay=xA[j];I(!w,zB[j]=yb)J(w==1,zH[j]=yh)J(w==2,zI[j]=yi)E(zL[j]=yl))
I(w==4,ya=sqz(mRa(z))))x(y))
V tilV(V*p,Ln,I w){L*a=p,v=T(0x706050403020100ll,0x3000200010000ll,1ll<<32,0)[w],
d=T(0x808080808080808ll,0x4000400040004ll,2ll<<32|2,1)[w];LN(a)i(PD((n-1>>3-w)+1,a),a[i]=v;v+=d)}
AL(tilL,P(n<0,n-NL?add(az(n),N(tilL(-n))):ed0())P(n>1<<30,ez0())Ax=an(tZ(n-1),n);tilV(xV,n,xt-tB);x)
A1(til,Xz(tilL(gl(x)))XZ(K("{x((*a)#&#)'1_a:|*\\|x,1}",x))XmM(x(_R(xx)))Xo(val(x))P(!xtA||xn,et1(x))x)
A1(whr,Xt(XF(et1(x))whr(enl(x)))XA(K("{$[`A~@x;(,&#'*'x),,'/x@\\:!0|/#'x:o'x;,&x]}",x))
Xm(Ay=kv(&x);idx(x,Nx(whr(y))))XM(et1(x))
x=N(cL(x));Ln=0;i(xn,n+=xl;P(n<0||xl<0,ed1(x)))Ct=tZ(xn-!!xn);P(t>tI,ez1(x))
Ay=an(t,n);xe(I(t==tB,B*a=yV;i(xn,j(xl,*a++=i)))
J(t==tH,H*a=yV;i(xn,j(xl,*a++=i)))
E( I*a=yV;i(xn,j(xl,*a++=i)))y))
A1(rev,Xm(Ay=kv(&x);am(rev(x),rev(y)))XM(Ay=kv(&x);aM(x,Nx(eac1f(y,rev))))Xt(x)x=mut(x);Ii=0,j=xn-1,w=Tz[xt];
W(i<j,I(!w,SWP(xb,xB[j]))J(w==1,SWP(xh,xH[j]))J(w==2,SWP(xi,xI[j]))E(SWP(xl,xL[j]))i++;j--)x)
A1(typ,x(as(TS[xt])))
A1(len,x(az(xN)))N _N(Ax/*0*/)_(XT(xn)Xm(_N(xy))XM(_n(xy)?_N(*_A(xy)):1)1)
S A1(cSI,Q(xtS||xtI)Ct=tS^tI^xt;xr-1?x(aV(t,xn,xV)):AT(t,x))
A1(unq,XT(P(xn<2,x)P(xtB||xtC,C a[256];Ms(a,0,SZ a);Ay=an(xt,0);i(xn,I(!a[xc],a[xc]=1;y=apc(y,xc)))x(y))
XS(cSI(unq(cSI(x))))K("{x@i@<i@:&@[;0;:;1]@~~':x@i:<x}",x))
XM(unq(val(x)))Xz(Ln=gl(x);P(n<0,ed0())rndD(n))et1(x))
A2(fil,YmMA(eac2f(x,y,exc))YF(y==au?x:x(y))Yt(fir(fil(x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