[NOIP Simulation Test]: platform (suffix array)

Topic Portal


Title Description

Through athletic, has a station called Homeward earth station, Homeward station there is called Meng Po cure my old woman selling. Life, both good and bad, I, drifting gains and losses are forgotten with the cure my bowl clean.
There are n-$ $ cure my bowl placed in a row, soup species does not exceed $ 26 $ species, we lowercase $ a \ sim z $ to represent one soup, soup and a weight of each $ {val } _i $.
You need to select a number of consecutive bowl of soup put down, the soup must meet the following conditions:
    . $ \ $ Alpha least one bowl of soup.
    $ \ beta. $ this substring (that is, those soup) all ranked in descending order sub-dictionary string in the original string is equal to this section of the weighted sum and soup.
Now you need to know the different kinds of soup election program.
Note that in various places, essentially the same substring ranking is the same and to repeat the calculation of the number of programs, such as the $ "aaa" $ this string ranked $ 1 $ substring is $ "aaa" $, appears once; ranked as $ 2 $ substring is $ "aa" $, appears twice; ranked as $ 3 to $ substring $ "a" $, there were three. (If you can not understand the meaning of the questions of interpretation to see a sample of $ 1,3 $).


Input Format

The first line of the character string of lower case letter n-$ $ a length of each character represents a soup.
$ $ N-th row of the second non-negative integer $ {val} _i $.


Output Format

Line an integer representing the number of sub-strings that can be selected from $ S $.
S $ next two lines each integers $ $ L, R $, respectively, each optional sub-string point and right end point of the left, according to a first ascending point of the left key, the right end of the second keyword ascending Sort.


Sample

Sample input 1:

abcd
10 0 1 1

Sample output 1:

3
1 1
3 4
4 4

Sample input 2:

aaaa
1 1 1 1

Sample Output 2:

0

Sample input 3:

aaa
1 1 1

Sample output 3:

2
1 2
2 3

Sample Input 4:

abdacdbcecbd
1 3 1 3 3 4 2 2 4 2 1 1

Sample output 4:

2
3 8
9 9


Data range and tips

Sample $ 1 $ explanation:

We put all the substring ranked in descending order according to the dictionary: $ d, cd, c, bcd, bc, b, abcd, abc, ab, a $.
Then the string $ D $ $ 1 to $ rank (the largest), and the weight of $ 1 $, can be selected.
$ Cd $ string Ranked $ 2 $, weights and is $ 2 $, can be selected.
A string $ $ $ $ 10 ranking weights and $ 10 $ may be selected.
This condition is not satisfied the other string, so there may be selected three strings.

Sample $ 3 $ explanation:

String $ a $ rankings are $ 3 $, weights and are $ 1 $.
String $ aa $ rankings are $ 2 $, weights and are $ 2 $, there are two strings $ aa $, are reserved for the $ 1 \ $ 2 and $ 2 \ 3 $.
String $ aaa $ rankings is $ 1 $, weights and are $ 3 $.

data range:

This question a total of $ 10 $ test points:

For the first $ 1 $ test points, to meet the $ n \ leqslant 50 $.

For the first $ 3 $ test points, to meet the $ n \ leqslant 1,000 $.

$ $ 4 for the first test, satisfy only from a string of characters, $ n \ leqslant 50,000 $.

For the first $ 5 $ test points, meet the same weight all the soup, $ n \ leqslant 50,000 $.

For the first test $ $ 6,7, satisfy $ n \ leqslant 50,000 $.

For the first $ 8,9,10 $ test points, to meet the $ n \ leqslant 200,000 $.

Guaranteed $ 0 \ leqslant {val} _i \ leqslant 1,000 $, and the number of sub-strings each test point to meet the requirements of not more than $ 200,000 $ a.


answer

Guess you like

Origin www.cnblogs.com/wzc521/p/11417561.html