#SGM0000034. A-hoy, Cướp biển! (Ahoy, Pirates!)
A-hoy, Cướp biển! (Ahoy, Pirates!)
Ahoy, Pirates!
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
A binary string is built from repeated patterns. Support setting a range to 1, setting it to 0, flipping it, and counting ones.
Input
The first line contains blocks. For each block, one line gives repetition count and the next line gives a binary pattern . Concatenate repeated times for all blocks. Then read and operations c a b.
F: set to 1.E: set to 0.I: flip all bits in .S: count ones in .
Indices are zero-based.
Output
For each S query, print the number of ones on its own line. The PHOJ version omits the original case/query labels.
Subtasks
- 20 points: expanded length , .
- 30 points: , .
- 50 points: , , each , , .
Examples
Input
1
1
00101
7
S 0 4
F 0 1
S 0 2
I 1 3
S 0 4
E 3 4
S 0 4
Output
2
3
3
1
Explanation
The initial string 00101 has 2 ones. After F 0 1 it is 11101, so S 0 2 returns 3. Flipping gives 10011 with 3 ones; clearing leaves 10000, so the final answer is 1.