The string s is copied into the SS and then thrown into the suffix automaton, from the root selection of the youngest son walk, walk n step is the answer ... At first I wanted to write a treap ... Later felt too troublesome. Just use the map ...
---------------------------------------------------------------------------
#include <cstdio>#include <cstring>#include <algorithm>#include <map>using namespace std;const int MAXN = 300009; struct Node {node* FA;map<int, node*> ch;int len;} POOL[MAXN << 2], *pt = Pool, *root, *last;node* newNode (int v) {pt->fa = NULL;pt->ch.clear ();Pt->len = v;return pt++;}void init () {pt = pool;root = last = NewNode (0);} void Extend (int c) {Node *p = last, *NP = NewNode (P->len + 1);For (; p &&!p->ch[c]; p = p->fa)P->ch[c] = NP;if (!p)np->fa = root;else {node* q = p->ch[c];if (p->len + 1 = = Q->len)NP->FA = q;else {node* NQ = NewNode (P->len + 1);NQ->FA = q->fa;Q->fa = Np->fa = NQ;for (map<int, node*>::iterator it = Q->ch.begin (); It! = Q->ch.end (); it++)Nq->ch[it->first] = it->second;For (; p && p->ch[c] = = q; p = p->fa)P->ch[c] = NQ;}}Last = NP;}int N, NUM[MAXN];int main () {init ();scanf ("%d", &n);for (int i = 0; i < N; i++)scanf ("%d", num + i);for (int i = 0; i < 2; i++)For (int j = 0; J < N; J + +)Extend (Num[j]);for (int i = 0; i < N; i++) {Map<int, Node*>::iterator it = Root->ch.begin ();if (i) Putchar (");printf ("%d", it->first);root = it->second;}return 0;}
---------------------------------------------------------------------------
2882: Process Time limit: ten Sec Memory Limit: MB
Submit: 268 Solved: 108
[Submit] [Status] [Discuss] DescriptionXiaomin and Xiao Yan are 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. InputThe first line is 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. Outputa row of n integers representing the value of the most aesthetically pleasing artifacts from left to right. 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
Bzoj 2882: Process (suffix automaton)