当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

7045:Fall with Soldiers

题目描述
Fall is playing a game about a war.

There are $n$ soldiers standing in a line. Some of them belong to the player, while others belong to the enemy. Due to the spies, the belonging of some of them is unknown. Now, as an artillery, the player may win this game under the following rules after identifying the belonging of each soldier:

Step 1: Choose a soldier which belongs to the player. There should be exactly two soldiers next to the chosen one, which means the chosen soldier should be neither at the beginning nor at the end of the line.

Step 2: Kill the soldiers next to the chosen one (the chosen one will remain alive).

Step 3: Repeat step 1 and step 2 until all the soldiers left belong to the same side (the player or the enemy).

The player wins if all the soldiers left belong to the player. Fall, as the player, wants to know the number of ways to identify the belonging of each soldier so that he can win.

However, soldiers may change their state (the player's troops, the enemies, or unknown). You need to calculate the answers after every change.
输入解释
The input consists of multiple test cases.

The first line contains an integer $T$ ($1 \leq T \leq 11$) -- the number of test cases.

For each test case:

In the first line, there are two integer $n,q$ ($1 \leq n,q \leq 2 \times 10^5$, $n$ is odd), which are the number of soldiers and the number of operations.

In the second line, there is a string $s$ of length $n$, which represents the initial soldier state. If $s_i$ is '1', the soldier belongs to you. If $s_i$ is '0', the soldier belongs to your enemy. If $s_i$ is '?', the belonging of this soldier is unknown.

In the next $q$ lines, each contains an integer $p$ ($1 \leq p \leq |s|$) and a charactor $c$, which means change $s_p$ to $c$.

It is guaranteed that the sum of $q$ over all test cases will not exceed $10^6$, $s_i,c \in \{'0','1','?'\}$


输出解释
For each test case, output the initial answer in a single line. Then output $q$ answers in $q$ lines, which are your answers after each change. All the answers should be output modulo $10^9+7$.
输入样例
6
5 1
01000
1 1
5 1
00000
3 1
15 4
1100????????111
8 ?
1 0
4 1
11 ?
15 4
0????000?0???0?
6 0
10 0
1 ?
10 ?
15 2
???????0?0???0?
4 0
1 0
15 2
00000000?0???0?
4 ?
4 ?
输出样例
0
0
0
1
247
247
247
253
253
368
368
368
736
1664
3616
1760
880
0
24
24

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-7045

最后修改于 2021-10-23T19:11:11+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
16000/8000MS(Java/Others) 524288/524288K(Java/Others)