如如下线段树代码中的合并部分,x,y为正在处理的区间,注意到x,y可能同时为0,直接打标记是不可取的。
if(!x||!y){
if(x){
t[x].maxx+=max2;
t[x].lazy+=max2;
}else{
x=y;
t[x].maxx+=max1;
t[x].lazy+=max1;
}
return;
}
改为
if(!x||!y){
if(x){
t[x].maxx+=max2;
t[x].lazy+=max2;
}else{
x=y;
if(x){
t[x].maxx+=max1;
t[x].lazy+=max1;
}
}
return;
}
即可,顺手提供一点样例,不太有强度,但也许可以帮到你。
input1:
6
6 6 2 3 3 2
1
1
3
3
2
output1:5
input2:
6
3 5 5 1 1 2
1
1
1
1
4
output2:5
input3:
6
2 4 6 4 1 6
1
1
1
4
4
output3:5