#P10796. 『SpOI - R1』我看到了,谢谢你们
『SpOI - R1』我看到了,谢谢你们
Problem Description
This problem contains multiple test cases.
Special note: in this problem, the definition of border is different. For strings , if there exists a prefix and a suffix of (they may be empty, and may also be itself) that are equal to , then is a border of .
There is a string of length . We use the information on this string to elect the president.
Let denote the prefix of of length . In particular, denotes the empty prefix (including the -th position). Now there are candidates standing on these prefixes, indexed by . Candidate corresponds to prefix . Each person has a number of votes and a cost .
A person whose number of votes is strictly more than half of the total votes can be elected president.
Initially, everyone is in the uncontrolled state. At each moment, any person who is uncontrolled and has been waiting all the time before can make one of the following three choices:
- Perform one vote for operation: cast their own votes to person at a cost of .
- Perform one canvass votes for operation:
- Spend to select person , and it is required that is a border of .
- For all , if is a border of , and is uncontrolled at this moment, then becomes controlled at the next moment, and all of their votes are cast to at a cost of .
- Wait for the next moment.
Each candidate hopes that no one else will become the president, and everyone is extremely smart. In particular, when operations overlap and cause one person's votes to need to be cast to multiple people, the overlapped person's votes can be cast independently to each of them and are all valid (you may think of their votes as splitting). Therefore, there may be multiple presidents.
You can intervene in this process. Specifically, at time you may operate on a candidate , making perform one specified choice, and you may also fix all variables involved in that choice. After that, can no longer make any choices, and the remaining people must start choosing from time . The cost of your intervention is the total cost of this choice made by .
Votes and costs will change times.
Each change modifies one entry of or one entry of . A vote count may become any positive integer, and a cost will only decrease or stay the same.
After each change, you need to find a person such that there exists a way for you to intervene on them so that they are guaranteed to become president, and the intervention cost is minimized. You only need to output this minimum cost.
It can be proven that such a person always exists.
This problem is forced online.
Input Format
The first line contains an integer , the number of test cases.
For each test case:
One line contains three integers , denoting the string length, the number of modifications, and whether it is forced online.
The next line contains a string of length . It is guaranteed that contains only lowercase English letters.
The next lines each contain two integers , in order describing the initial votes and costs of candidates to .
The next lines each contain three integers . Let be the absolute value of the previous output answer. Then $o\gets o'\oplus(type\times lst),p\gets p'\oplus(type\times lst),x\gets (|x'|\oplus(type\times lst))\times (-1)^{[x'\leq 0]}$ (where is the Iverson bracket), and then:
- When , modify to .
- When , modify to . It is guaranteed that .
Output Format
Output lines in total.
The first line outputs the minimum intervention cost in the initial state.
After that, output the minimum intervention cost after each modification, for a total of lines.
3
2 1 0
aa
6 1
2 -1
3 2
1 0 2
19 0 0
happythbirthdayshun
1000000000 8
1000000000 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 1
1 0
1 0
5 6 1
acbac
1 3
2 4
1 -5
3 6
2 -3
3 1
11 10 12
9 13 108
8 12 8
10 9 0
6 1 4
4 7 1
1
0
17
9
8
-9
8
-4
-5
-5
Hint
Sample #1 Explanation
For the first test case:
Consider the state before the first modification. There are votes in total, so being elected president requires votes.
Intervene on candidate , and choose the first option. After performing one vote for operation with cost , candidate gets votes and directly meets the requirement for president. It can be proven that this is the minimum-cost answer.
After the first modification, there are votes in total, so being elected president requires votes.
Intervene on candidate , and choose the second option. After performing one canvass votes for operation, candidate will get votes, and the total cost is . They directly meet the requirement for president. It can be proven that this is the minimum-cost answer.
For the third test case, after removing the forced-online encoding, the modification operations are:
- ;
- ;
- ;
- ;
- ;
- .
Constraints
Please note the impact of constant factors on program efficiency.
This problem enables subtask bundling and subtask dependencies.
For of the data, , , , , and it is guaranteed at any time that , .
It is guaranteed that the string contains only lowercase letters.
For any single modification, it is guaranteed that is or , and . When , ; when , .
In particular, each entry in is monotone non-increasing during the operations.
| Subtask | Special Property | Score | Subtask Dependencies | |||
|---|---|---|---|---|---|---|
| 1 | None | None | ||||
| 2 | 1 | |||||
| 3 | None | |||||
| 4 | ||||||
| 5 | ||||||
| 6 | ||||||
| 7 | None | 1,2,3,4,5,6 |
Special property : it is guaranteed that .
Special property : each character in the string is independently and uniformly random among the lowercase letters.
Special property : the string contains only .
Special property : it is guaranteed that .
Translated by ChatGPT 5