Sequence operation
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8463 Accepted Submission(s): 2555
Problem Description
lxhgww got a sequence contains n characters which are all '0's or '1's.
We have five operations here:
Change operations:
0 a b change all characters into '0's in [a , b]
1 a b change all characters into '1's in [a , b]
2 a b change all '0's into '1's and change all '1's into '0's in [a, b]
Output operations:
3 a b output the number of '1's in [a, b]
4 a b output the length of the longest continuous '1' string in [a , b]
Input
T(T<=10) in the first line is the case number.
Each case has two integers in the first line: n and m (1 <= n , m <= 100000).
The next line contains n characters, '0' or '1' separated by spaces.
Then m lines are the operations:
op a b: 0 <= op <= 4 , 0 <= a <= b < n.
Output
For each output operation , output the result.
Sample Input
1 10 10 0 0 0 1 1 0 1 0 1 1 1 0 2 3 0 5 2 2 2 4 0 4 0 3 6 2 3 7 4 2 8 1 0 5 0 5 6 3 3 9
Sample Output
Author
lxhgww&&shǎ崽
Source
HDOJ Monthly Contest – 2010.05.01
Recommend
lcy
题意:给你个01串。有以下几种操作:
1.把[l,r]区间的所有数都置为0或1
2.把[l,r]区间的所有数都置为其相反数
3.求[l,r]区间内的1的个数
4.求[l,r]区间内的最长的连续的'1'的个数
解题思路:线段树,因为只有0和1,所以只要记录一下一个区间是否为同一个数,然后成段更新即可
#include
#include
#include
#include
#include
#include
#include