Two times Unicom gate: Bzoj 1031: [JSOI2007] character encryption cipher
/*bzoj 1031: [JSOI2007] character encryption cipher Copy the original string once and then ask for the suffix array again*/#include<cstdio>#include<cstring>#defineMax 1000008voidRead (int&Now ) {RegisterCharWord =GetChar (); for(now =0; Word <'0'|| Word >'9'; Word =GetChar ()); for(; Word >='0'&& Word <='9'; now = now *Ten+ Word-'0');} InlinevoidSwap (int*&a,int*&b) { int*now =A; A=b; b=Now ;} intSa[max], Rank[max];intHeight[max];CharLine[max];intStr_1[max], Str_2[max];intN, M;voidGet_suffix () {Registerinti; Static intC[max], *x = str_1, *y =str_2; for(i =0; i < M; C[i + +] =0); for(i =0; i < N; C[x[i] = Line[i]] + +, I + +); for(i =1; i < M; C[i] + = c[i-1], I + +); for(i = N-1; I >=0; sa[--C[x[i]] = i--); RegisterintPOS; POS=1; for(intj =1; POS < N; J <<=1, M =POS) {POS=0; for(i = n-j; i < N; Y[pos + +] = i + +); for(i =0; i < N; i + +) if(Sa[i] >=j) Y[pos+ +] = Sa[i]-J; for(i =0; i < M; C[i + +] =0); for(i =0; i < N; C[x[y[i]] + +, I + +); for(i =0; i < M; C[i] + = c[i-1], I + +); for(i = N-1; I >=0; sa[--C[x[y[i]] = y[i--]); Swap (x, y); POS=1; x[sa[0]] =0; for(i =1; i < N; i + +) X[sa[i]]= (Y[sa[i-1] [= Y[sa[i]] && y[sa[i-1] + j] = = Y[sa[i] + j] && Sa[i-1] + J < n && Sa[i] + j < n)? POS-1: Pos + +; }}intMain (intargcChar*argv[]) {scanf ("%s", line); N=strlen (line); M= the; for(inti =0; i < N; + + i) Line[i + N] =Line[i]; Line[n<<1] =0; intP = N; N =2* N +1; Get_suffix (); N=P; for(inti =0; I < N *2+1; i + +) if(Sa[i] < N) printf ("%c", Line[n + sa[i]-1]); return 0;}
Bzoj 1031: [JSOI2007] character encryption cipher