Time Limit:10 Sec Memory limit:128 MB
submit:684 solved:309 Description Xiaomin and Xiao Yan is a pair of good friends. They are playing a magical game called Minecraft. They are now going to make a strip of crafts made of blocks. But the blocks are now messy, and because of the machine's requirements, they can only do the most left-hand block of the handicraft on the far right. They thought, in this one operation alone, the most beautiful crafts can be more beautiful. Two crafts Beautiful comparison method is, from the beginning to compare, if the first position of the block is not the same then who the defect degree is small, then who is more beautiful, if the same then continue to compare the i+1 block. If it's all the same, then the two crafts are just as beautiful. Input first line two integer n, which represents the number of squares. The second row n integers, each of which outputs the value of the square defect in order from left to right. Output is a row of n integers, representing the value of the most beautiful handicraft from left to right defect degrees. Sample Input
10
10 9 8 7 6 5 4 3 2 1
Sample Output
1 9 8 7 6 5 4 3 2HINT
"Data size and conventions"
For 20% of data, n<=1000
For 40% of data, n<=10000
For 100% of data, n<=300000
Source
In fact, it is to ask for the minimum notation.
Automatic suffix machine
In fact, the minimum notation does not need a suffix automaton, pure when the open mind (it is not to see can use the suffix automata did not think of anything else)
The Magical O (n) Scanning solution: http://www.cnblogs.com/SilverNebula/p/6420632.html
The original string is amplified to twice times, then the suffix automaton is built.
The suffix automata is a dag map that runs to the finish line no matter how it runs. Then starting from the starting point, each time the target value of the smallest side walk, even walk n steps to get the smallest representation of the string.
But the "string" of the problem is a sequence, not discretization of the array. Think of using set, and set is not as convenient as map, and finally used a map.
1 /*by Silvern*/2#include <algorithm>3#include <iostream>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <map>8 using namespacestd;9 Const intmxn=1200010;Ten intRead () { One intx=0, f=1;CharCh=GetChar (); A while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} - while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} - returnx*F; the } - intans[mxn],act=0; - structsam{ -map<int,int>T[MXN]; + intFA[MXN],L[MXN]; - ints,last,cnt; + voidInit () {s=last=cnt=1;return;} A voidAddintc) { at intp=last,np=++cnt;last=NP; -l[np]=l[p]+1; - for(;p &&!t[p].count (c);p =fa[p]) t[p][c]=NP; - if(!p) fa[np]=S; - Else{ - intq=T[p][c]; in if(l[q]==l[p]+1) {fa[np]=q;} - Else{ to intnq=++cnt;l[nq]=l[p]+1; +t[nq]=T[q]; -fa[nq]=Fa[q]; thefa[q]=fa[np]=NQ; * for(;p && t[p][c]==q;p=fa[p]) t[p][c]=NQ; $ }Panax Notoginseng } - } the voidSolveintN) { + intp=s,tmp=0; Aact=0; the while(tmp<N) { +map<int,int>::iterator i=T[p].begin (); - //printf ("%d%d\n", i->first,i->second); $Ans[++act]=i->First ; $P=i->second; -tmp++; - } the } - }sa;Wuyi intN; the intA[MXN]; - intMain () { Wu inti,j; -n=read (); About sa.init (); $ for(i=1; i<=n;i++){ -a[i]=read (); - Sa.add (A[i]); - } A for(i=1; i<=n;i++) Sa.add (A[i]); + sa.solve (n); the for(i=1; i<n;i++) printf ("%d", Ans[i]);p rintf ("%d\n", Ans[n]); - return 0; $}
Bzoj2882 process [Western algorithm]