Kim is a magician, he can use n kinds of magic, number from 1 to n. We use string Si to describe magic i. Magic Si will make Wi points of damage. Note that Wi may change over time.
Kim obey the following rules to use magic:
Each turn, he picks out one magic, suppose that is magic Sk, then Kim will use all the magic i satisfying the following condition:
1. Wi<=Wk
2. Sk is a suffix of Si.
Now Kim wondering how many magic will he use each turn.
Note that all the strings are considered as a suffix of itself.
Input
First line the number of test case T. (T<=6)
For each case, first line an integer n (1<=n<=1000) stand for the number of magic.
Next n lines, each line a string Si (Length of Si<=1000) and an integer Wi (1<=Wi<=1000), stand for magic i and it’s damage Wi.
Next line an integer Q (1<=Q<=80000), stand for there are Q operations. There are two kinds of operation.
“1 x y” means Wx is changed to y.
“2 x” means Kim has picked out magic x, and you should tell him how many magic he will use in this turn.
Note that different Si can be the same.
Output
For each query, output the answer.
Sample Input
15abracadabra 2adbra 1bra 3abr 3br 252 32 51 2 52 32 2
Sample Output
3121
题意:
给n个长度<=1000的字符串S[i](仅由小写字母构成),每个字符串有权值w[i]
有两种操作
2 k 选中第k个字符串,问你有多少个字符串满足w[i]<=w[k]而且S[k]是S[i]的后缀
1 k y 把第k个字符串的权值修改为
暴力HASH 预处理下后缀
然后暴力查询
1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include