#7603. [MCO 2024] Knights
[MCO 2024] Knights
[MCO 2024] Knights
题目描述
There are $N$ knights labeled $1$ to $N$ standing in a row. The $i$-th knight has power $P_i$.The knights are competing in a jousting tournament. To do so, each knight will hold a sword pointing either to the left or to the right. The -th knight will point their sword to the left if and to the right if where is a binary string of length .
A joust is defined as the following process:
- Initially all knights are alive.
- Let be the list of knights still alive arranged in increasing order of label and be the size of .
- For each from to . If the -th knight has an adjacent knight with bigger power pointing their sword at the -th knight's direction, then mark the knight as Formally the -th knight will be marked as dead if one of the following condition is true.
- and and
- and and
- Return to step 2 if there is at least one knight in marked as dead.
Now you are given queries, each query are of the form:
- Given integer (), change to .
After each query, find the number of knights alive after a joust is performed.
Do note that knights do not stay dead after a joust.
输入格式
The first line contains two space-separated integers $N$ and $Q$ ($1 \le N,Q\le 10^6$) -- the size of $P$ and the number of queries.The second line contains space-separated integers ().
The third line contains a binary string of length .
Then lines follow. Each of the lines contains a single integer () denoting a query to change to .
输出格式
Output $Q$ integers $q_1, q_2, \ldots, q_n$ in order on $Q$ lines, where $q_i$ is the number of knights alive after performing a joust after the $i$-th query.5 3
2 1 3 4 3
11011
1
3
4
2
4
2
10 5
10 1 2 3 8 9 4 5 7 6
0111100110
10
5
6
5
1
5
5
3
6
1
提示
### NoteIn the first sample input, after the first query, becomes 01011.
Initially, the (labels of) the knights alive are . After one iteration, the knights remaining are . After the second iteration, the knights remaining are . After the third iteration, no new knight dies, so 2 knights remain after a joust.
After the second query, becomes 01111.
After one iteration, the knights remaining are . After the second iteration, no new knight dies, so 4 knights remain after a joust.
Scoring
Subtask 1 (6 points):
Subtask 2 (9 points): for
Subtask 3 (17 points): if and the answer for each query is guaranteed to be at most .
Subtask 4 (19 points): if
Subtask 5 (19 points):
Subtask 6 (30 points): No additional constraints 标签: P15283|2024|MCC/MCO(马来西亚)