#DSU0000090. Giáo sư Higashikata (Professor Higashikata)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Giáo sư Higashikata (Professor Higashikata)
Professor Higashikata
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a binary string of length . In one operation, swap the characters at two distinct positions of ; each swap costs .
For each of the intervals , let be the corresponding substring of the current , and define
where denotes concatenation. Intervals may overlap or coincide, so a character of may occur multiple times in .
There are updates; update flips the bit . After each flip, find the minimum number of swaps needed to make lexicographically maximum among all strings obtainable by swapping characters of . Only report the minimum number; the swaps are hypothetical and are not actually carried out. Thus, only the bit flips persist between updates.
For equal-length binary strings, 1 is larger than 0 at the first position of difference.
Input
The first line contains , followed by binary string , interval lines , and flip positions .
Output
Print one integer after each update: the minimum number of required swaps.
Subtasks
- Subtask 1 (20 points): , , , .
- Subtask 2 (30 points): , , , .
- Subtask 3 (50 points): , , , .
Example
Input
2 2 4
01
1 2
1 2
1
1
2
2
Output
0
1
0
1
Explanation
Both intervals are . When becomes 11, zero swaps are needed. For 01, swapping the two bits produces 10, requiring one swap.