対応表を作るイメージ? DIM B[N]:COPY B,A:SORT B DIM C[1]:C[0]=B[0] FOR D=0 TO N-1 IF B[D]!=C[LEN(C)-1] THEN PUSH C,B[D] NEXT DIM E[LEN(C)] F=0:G=0 FOR D=0 TO N-1 IF B[D]==C[F] THEN G=G+1 ELSE E[F]=G:F=F+1:G=1 NEXT E[F]=G FOR D=0 TO N-1 FOR F=0 TO LEN[C]-1 IF A[D]==C[F] THEN A[D]=E[F]:BREAK NEXT NEXT END Nを10万にすると分単位で持っていかれますが、さっきよりは速いはず。
var b[n] var c[n] var t[n] var i,j var u var m=n-1 for i=0 to m t[i]=i next copy b, a sort b, t i=0 while i<n u=0 while i+u<n&&b[i]==b[i+u] u=u+1 wend j=i+u-1 for i=i to j c[i]=u next wend for i=0 to m a[i]=c[t[i]] next