#SGM0000043. Đảo bit và nghịch thế (Lazy Segment Tree)
Đảo bit và nghịch thế (Lazy Segment Tree)
Lazy Segment Tree
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Maintain a binary array under range flips and range inversion-count queries.
Input
The first line contains and the next line . Each query T L R is:
1 L R: replace each in the range by .2 L R: count pairs in the range with .
Output
Print the inversion count for every type 2 query.
Subtasks
- 20 points: .
- 30 points: .
- 50 points: , every is 0 or 1.
Examples
Input
5 5
0 1 0 0 1
2 1 5
1 3 4
2 2 5
1 1 3
2 1 2
Output
2
0
1
Explanation
Initially there are two inversions. Flipping positions 3 and 4 makes range all ones, hence zero inversions. After the next flip, the first two values are 1 0, giving exactly one inversion.