cswork / OAOpen practice workspace

DatabricksOA #3

Binary String Count / Flip Queries

Estimated MediumJudge-ready

Topics (AI-labelled)Prefix & RangesSimulation

Given a string of 0s and 1s, process the operations in order. flip swaps 0 and 1 throughout the string; count i asks for the number of 0s in the current string from index 0 to i (inclusive).

Standard input/output, this site's supplementary ranges, and the examples follow this problem's description.

Input

The first line contains n q (1≤n≤200000, 0≤q≤8000); the second line contains a binary string of length n; then q lines of operations: flip or count i, where 0≤i<n. The ranges of q and the indices are site supplements that make the standard input protocol explicit and keep the standard output within the judge's limit. Indices in operations are counted from 0.

Output

Output the counts in the order the queries appear, separated by spaces; if there are no count operations, output an empty line.

Example 1

Input:

7 6
1111010
count 4
count 6
flip
count 4
flip
count 2

Output:

1 2 4 0

Example 2

Input:

4 5
0000
count 0
flip
count 3
flip
count 1

Output:

1 0 2

Example 3

Input:

1 4
1
flip
count 0
flip
count 0

Output:

1 0

Editorial

Loading solution…