×_7_9_2013 G: Matrix

Problem H: Lexicographically Maximum Subsequence

Time Limit: 2 Sec   Memory Limit: 128 MB
Submit: 1   Solved: 1
[ Submit][ Status][ Web Board]

Description

You’ve got string S and m queries. Each query asks you to calculate the hash value for the lexicograph-
ically 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= yrand
xr+1> yr+1. Characters in lines are compared like their ASCII codes.
The hash value for string s of length n is
Sum(s ip n−i)%mod,1≤i≤n, p = 1000007, mod = 1000000007.

Input

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.

Output

Print the hash value of lexicographically maximum subsequence of string s for each query in separate
line.

Sample Input

abeced 2 1 3 1 6 kjihgfedcba 1 1 11

Sample Output

101 514298749 888634539


转载于:https://my.oschina.net/dianpaopao/blog/144387

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值