1616 - Lexicographically Maximum Subsequence
Time Limit : 2 Second
Memory Limit : 128 MB
- You've got string S and m queries. Each query asks you to calculate the hash value for the lexicographically maximum subsequence of substring S[l….r].
We'll call a non-empty string S[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... < pk ≤ |s|) a subsequence of string s = s1s2... s|s|.
String x = x1x2... x|x| is lexicographically larger than string y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or exists such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1. Characters in lines are compared like their ASCII codes.
The hash value for string s of length n is .
- There are multiple cases, process to the EOF. Each cases begins with a line contains a non-empty string s, consisting only of lowercase English letters. The string's length doesn't exceed 10^6. The second line contains an integer m(1<=m<=10^6), indicate that there are m queries. Then the next m lines contains m queries, each line describe the query with two integer l and r.
- Print the hash value of lexicographically maximum subsequence of string sfor each query in separate line.
- sample input
abeced 2 1 3 1 6 kjihgfedcba 1 1 11
- sample output
101 514298749 888634539
- The 7th(2012) ACM Programming Contest of HUST Problem Setter: Shucheng Zhong