题目描述
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
There are $N$ subatomic particles lined up in a row. There are two types: protons and electrons. Protons have a positive charge and are represented by $1$, while electrons have a negative charge and are represented by $0$.
Our current understanding of physics gives us a way to predict how the particles will be spaced out, if we know their charges. Two adjacent particles will be separated by $1$ unit if they have opposite charges, and $2$ units if they have the same charge.
When Chef is not in the kitchen, he is doing physics experiments on subatomic particles. He is testing the hypothesis by having $N$ particles in a row, and he will change the charge of a particle $K$ times. In the $i$-th update, he will change the charge of the $Q_{i}$-th particle. After each update, find the distance between the first and last particle.
Note: Each update is persistent for further updates.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains three lines of input.
The first line contains two integers $N$, $K$.
The second line contains a string $S$ of length $N$, where $S_{i}$ represents the initial charge on $i$-th particle.
The third line contains $K$ integers $Q_{1}, Q_{2}, \ldots, Q_{K}$, the positions of the changed particles.
------ Output ------
For each test case, output $K$ lines, where the $i$-th line contains the answer after the updates $Q_{1},\ldots, Q_{i}$ have been made.
------ Constraints ------
$1 ≤ T ≤ 5$
$1 ≤ N, K ≤ 10^{5}$
$S$ contains only $0$ and $1$ characters.
$1 ≤ Q_{i} ≤ N$
The sum of $K$ over all testcases is at most $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
1
3 3
010
2 1 3
----- Sample Output 1 ------
4
3
2
----- explanation 1 ------
Update 1: After reversing the parity of particle $2$, the new configuration is $000$. Since all the particles have a similar charge, each is separated from the previous by a distance of $2$ units. So the location of particle $3$ is $2 + 2 = 4$ units from the first particle.
Update 2: After reversing the parity of particle $1$, the new configuration is $100$. Here, the charges of particles $1$ and $2$ differ, so they are separated by $1$ unit. The charges of particles $2$ and $3$ agree, so they are separated by $2$ units. So, the location of particle $3$ is $1 + 2 = 3$ units from the first particle.
Update 3: After reversing the charge of particle $3$, the new configuration is $101$. Here, particles $1$ and $2$ are separated by $1$ unit and particles $2$ and $3$ are separated by $1$ unit. So the location of particle $3$ is $1 + 1 = 2$ units from the first particle.
输入格式
见题面
输出格式
见题面