#P5445. [APIO2019] 路灯
[APIO2019] 路灯
Description
A self-driving taxi is driving along a street in Innopolis. There are stops on the street, which divide the street into road segments. Each segment has a street lamp. When the -th lamp is on, it lights up the segment connecting stops and . Otherwise, this segment is dark.
For safety reasons, the taxi can only drive on lit segments. In other words, the taxi can travel from stop to stop if and only if the segments connecting stops and , and , , and are all lit.
After some unexpected failures or repairs, the street lamps on the street may be on or off.
You are given the initial states of the street lamps at time . Then at times , one of the following two events happens at each time:
-
: Toggle the state of the -th street lamp. Specifically, if it was on, it becomes off; if it was off, it becomes on.
-
: The head of the taxi department wants to know: from time up to the current time, how many times satisfy that the taxi can travel from stop to stop .
Please help answer these queries for the head of the taxi department.
Input Format
The first line contains two integers and , representing the number of street lamps and the number of time moments.
The second line contains a string representing the initial states of the street lamps. means the -th lamp is initially on, and means the -th lamp is initially off.
The next lines each describe the event at a time moment. The -th of these lines describes the event that happens at time :
-
: At this time moment, the state of the -th street lamp is toggled.
-
: Compute, from time up to this time moment, how many time moments satisfy that the taxi can travel from stop to stop .
At least one event is .
Output Format
For each event, output a single integer on its own line, which is the answer to that query.
5 7
11011
query 1 2
query 1 2
query 1 6
query 3 4
toggle 3
query 3 4
query 1 6
1
2
0
0
1
2
Hint
For all data, , , , .
The detailed additional constraints and scores for subtasks are as follows.
| Subtask | Additional Constraints | Score |
|---|---|---|
| 1 | , | 20 |
| 2 | For all events, holds | |
| 3 | For all events, the -th lamp will be turned on | |
| 4 | All events happen before the first event | |
| 5 | No additional constraints |
Translated by ChatGPT 5
京公网安备 11011102002149号