#P99. [NOI 2025 Day 2] 绝对防御
[NOI 2025 Day 2] 绝对防御
Person in Charge
Problem Description
Little Q is playing a turn-based card game called "Absolute Defense" against a computer.
Little Q has a deck of size , containing two types of cards: attack cards and defense cards. At the start of the game, Little Q draws cards from the top of the deck as his initial hand. He then engages in several rounds of battle with the computer.
At the beginning of each battle round, Little Q draws cards from the top of the deck. Specifically, if only card remains in the deck, Little Q draws only that card. Each battle round consists of two turns:
- First turn: Little Q is the attacker, and the computer is the defender.
- Second turn: Little Q is the defender, and the computer is the attacker.
In each turn, the attacker must choose an attack card from their hand to attack, and the defender must play a defense card from their hand to defend. Failure to play the required card results in an immediate loss.
The computer has an unlimited number of attack and defense cards, meaning it can always play the corresponding card. To balance the computer's strength, Little Q can use a special ability: when Little Q is the defender, he can play an attack card from his hand to defend. This ability can be used only once every battle rounds, meaning that after using the ability, it cannot be used again for the next battle rounds.
Under these rules, Little Q's goal is to survive the computer's fierce attacks, i.e., to empty the deck at the end of a battle round. Specifically, if the deck is already empty at the start of the game, Little Q immediately achieves his goal. Little Q wants to find the smallest initial draw count that allows him to achieve the goal.
Little Q finds this problem too simple, so he adds modification operations. The -th () modification operation is given a positive integer , which changes the type of the -th card from the top to the bottom of the deck, i.e., converting an attack card to a defense card or vice versa. For the initial deck and after each modification, you need to determine the smallest initial draw count that allows Little Q to achieve the goal.
Input Format
This problem contains multiple test cases.
The first line of input contains two non-negative integers and , representing the test case ID and the number of test cases, respectively. indicates a sample test case.
Next, each test case is input sequentially. For each test case:
The first line contains two non-negative integers and , representing the size of the deck and the number of modifications, respectively.
The second line contains a string of length , where each character represents the type of the -th card from the top to the bottom of the deck. Here, indicates an attack card, and indicates a defense card.
The -th line () contains a positive integer , representing the -th card from the top to the bottom of the deck to be modified.
Output Format
For each test case, let the initial answer be , and the answer after the -th () modification be . Output a line with positive integers , representing the smallest initial draw count and its value after each modification that allows Little Q to achieve the goal.
Samples
0 3
5 1
01010
4
7 0
0001000
10 0
0001010000
1 1
3
2
Sample 1 Explanation
This sample contains three test cases.
For the first test case:
-
Initially, the deck is . If the initial draw count is , one possible play sequence for Little Q is:
- Initial hand: ;
- Draw two cards from the top, play one attack card and one defense card, hand becomes ;
- Draw two cards from the top, play one attack card and one defense card, hand becomes , and the deck is now empty.
Since the minimum initial draw count is , .
-
After the first modification, the deck becomes . If the initial draw count is , one possible play sequence for Little Q is:
- Initial hand: ;
- Draw two cards from the top, play one attack card and one defense card, hand becomes ;
- Draw two cards from the top, play one attack card and use the special ability to play another attack card for defense, hand becomes , and the deck is now empty.
Since the minimum initial draw count is , .
For the second test case:
If the initial draw count is , one possible play sequence for Little Q is:
-
Initial hand: ;
-
Draw two cards from the top, play one attack card and one defense card, hand becomes ;
-
Draw two cards from the top, play one attack card and use the special ability to play another attack card for defense, hand becomes , and the deck is now empty.
It can be proven that no smaller initial draw count can empty the deck, so the answer is .
For the third test case:
If the initial draw count is , one possible play sequence for Little Q is:
-
Initial hand: ;
-
Draw two cards from the top, play one attack card and use the special ability to play another attack card for defense, hand becomes ;
-
Draw two cards from the top, play one attack card and one defense card, hand becomes ;
-
Draw two cards from the top, play one attack card and one defense card, hand becomes , and the deck is now empty.
It can be proven that no smaller initial draw count can empty the deck, so the answer is .
Sample 2
See the files defense/defense2.in and defense/defense2.ans in the contestant's directory.
This sample satisfies the constraints of test case .
Sample 3
See the files defense/defense3.in and defense/defense3.ans in the contestant's directory.
This sample satisfies the constraints of test cases .
Sample 4
See the files defense/defense4.in and defense/defense4.ans in the contestant's directory.
This sample satisfies the constraints of test cases .
Sample 5
See the files defense/defense5.in and defense/defense5.ans in the contestant's directory.
This sample satisfies the constraints of test case .
Sample 6
See the files defense/defense6.in and defense/defense6.ans in the contestant's directory.
This sample satisfies the constraints of test cases .
Data Range
Let and be the sums of and across all test cases in a single test point, respectively. For all test data, the following guarantees hold:
- ;
- , ;
- , ;
- For all , ;
- For all , .
| Test Case ID | Special Properties | |||
|---|---|---|---|---|
| None | ||||
| None | ||||
- Special Property : For all , is independently and uniformly randomly generated from .
- Special Property : All are distinct, and for all , .
- Special Property : All are distinct, and for all , .
- Special Property : For all , is independently and uniformly randomly generated from .
- Special Property : For all , .