Reporting Documents
Time limit1sMemory limit2048 MB
Given a binary string with point flips, each query asks for the number of zero positions among x, x+k, x+2k, and so on, up to N.
- Level
Medium6 of 10
- Topics
- Array, Math, Implementation
- Solved
- No attempts yet
Problem
Each citizen of the ICPC Kingdom must always carry the documents issued by the kingdom, numbered from to . Guards often ask random citizens for their documents during patrols.
Adrian is a citizen of the ICPC Kingdom and also carries these documents. Through negligence, some of them may be missing. The status of his documents is given by a string of length , where if document is on his hand and if it is missing.
Each of the next days, exactly one of the following happens.
- : Adrian finds his missing document , so becomes . It is guaranteed that right before this event.
- : Adrian loses document , so becomes . It is guaranteed that right before this event.
- : A guard asks Adrian for documents for every integer such that , where . Adrian pays a fine of 1 coin for each requested document he cannot provide at that moment.
For each event of type , count the total fine Adrian must pay.
Input
The first line contains an integer (), the number of documents. The second line contains a string of length , where the -th character is (), the initial status of document .
The third line contains an integer (), the number of days. Each of the next lines describes one event and begins with an integer (). If or , the line contains one more integer (). If , the line contains two more integers and (). There is at least one event of type .
Output
For each event of type , print the number of coins Adrian must pay on its own line.