#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 nn, containing two types of cards: attack cards and defense cards. At the start of the game, Little Q draws k (1kn)k \ (1 \le k \le n) 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 22 cards from the top of the deck. Specifically, if only 11 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 33 battle rounds, meaning that after using the ability, it cannot be used again for the next 22 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 kk that allows him to achieve the goal.

Little Q finds this problem too simple, so he adds qq modification operations. The ii-th (1iq1 \le i \le q) modification operation is given a positive integer xix_i, which changes the type of the xix_i-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 kk 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 cc and tt, representing the test case ID and the number of test cases, respectively. c=0c = 0 indicates a sample test case.

Next, each test case is input sequentially. For each test case:

The first line contains two non-negative integers nn and qq, representing the size of the deck and the number of modifications, respectively.

The second line contains a string s1s2sns_1 s_2 \ldots s_n of length nn, where each character represents the type of the ii-th card from the top to the bottom of the deck. Here, si=0s_i = 0 indicates an attack card, and si=1s_i = 1 indicates a defense card.

The (i+2)(i + 2)-th line (1iq1 \le i \le q) contains a positive integer xix_i, representing the xix_i-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 k0k_0, and the answer after the ii-th (1iq1 \le i \le q) modification be kik_i. Output a line with q+1q+1 positive integers k0,k1,,kqk_0, k_1, \ldots, k_q, 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 0101001010. If the initial draw count is 11, one possible play sequence for Little Q is:

    • Initial hand: {0}\{0\};
    • Draw two cards from the top, play one attack card and one defense card, hand becomes {0}\{0\};
    • Draw two cards from the top, play one attack card and one defense card, hand becomes {0}\{0\}, and the deck is now empty.

    Since the minimum initial draw count is 11, k0=1k_0=1.

  • After the first modification, the deck becomes 0100001000. If the initial draw count is 11, one possible play sequence for Little Q is:

    • Initial hand: {0}\{0\};
    • Draw two cards from the top, play one attack card and one defense card, hand becomes {0}\{0\};
    • Draw two cards from the top, play one attack card and use the special ability to play another attack card for defense, hand becomes {0}\{0\}, and the deck is now empty.

    Since the minimum initial draw count is 11, k1=1k_1=1.

For the second test case:

If the initial draw count is 33, one possible play sequence for Little Q is:

  • Initial hand: {0,0,0}\{0,0,0\};

  • Draw two cards from the top, play one attack card and one defense card, hand becomes {0,0,0}\{0,0,0\};

  • Draw two cards from the top, play one attack card and use the special ability to play another attack card for defense, hand becomes {0,0,0}\{0,0,0\}, and the deck is now empty.

    It can be proven that no smaller initial draw count can empty the deck, so the answer is 33.

For the third test case:

If the initial draw count is 22, one possible play sequence for Little Q is:

  • Initial hand: {0,0}\{0,0\};

  • Draw two cards from the top, play one attack card and use the special ability to play another attack card for defense, hand becomes {0,1}\{0,1\};

  • Draw two cards from the top, play one attack card and one defense card, hand becomes {0,1}\{0,1\};

  • Draw two cards from the top, play one attack card and one defense card, hand becomes {0,0}\{0,0\}, and the deck is now empty.

    It can be proven that no smaller initial draw count can empty the deck, so the answer is 22.

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 22.

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 575 \sim 7.

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 9,109,10.

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 1111.

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 121412 \sim 14.

Data Range

Let NN and QQ be the sums of nn and qq across all test cases in a single test point, respectively. For all test data, the following guarantees hold:

  • 1t1051 \le t \le 10^5;
  • 1n2×1051 \le n \le 2 \times 10^5, N5×105N \le 5 \times 10^5;
  • 0q2×1050 \le q \le 2 \times 10^5, Q5×105Q \le 5 \times 10^5;
  • For all 1in1 \le i \le n, si{0,1}s_i \in \{0, 1\};
  • For all 1iq1 \le i \le q, 1ki<n1 \le k_i < n.
Test Case ID nn \le qq \le N,QN, Q \le Special Properties
11 2020 6060 None
22 10210^2 10310^3
3,43,4 30003000 10410^4
575 \sim 7 10510^5 00 3×1053 \times 10^5
88 2×1052 \times 10^5 200200 5×1055 \times 10^5
9109 \sim 10 10510^5 3×1053 \times 10^5 AB\mathrm{A B}
1111 AC\mathrm{A C}
121412 \sim 14 AD\mathrm{A D}
151715 \sim 17 E\mathrm{E}
18,1918,19 None
2020 2×1052 \times 10^5 5×1055 \times 10^5
  • Special Property A\text{A}: For all 1in1 \le i \le n, sis_i is independently and uniformly randomly generated from {0,1}\{0,1\}.
  • Special Property B\text{B}: All xix_i are distinct, and for all 1iq1 \le i \le q, sxi=1s_{x_i} = 1.
  • Special Property C\text{C}: All xix_i are distinct, and for all 1iq1 \le i \le q, sxi=0s_{x_i} = 0.
  • Special Property D\text{D}: For all 1iq1 \le i \le q, xix_i is independently and uniformly randomly generated from [1,n][1, n].
  • Special Property E\text{E}: For all 0i<q0 \le i < q, 1ki451 \le k_i \le 45.