[Bzoj3064] CPU monitoring

Consider first the maximum no history section, each section maintaining a tuple (x, y) with the segment tree, interval represents the number of all modifications to x and y taken together max, then we would support the tag and incorporated in the ?
Review: If changes to the (x, y) a (x ', y'), then that is (x + x ', max ( y + x', y '))
merge: If (x1, y1) and ( x2, y2) merger, it is (max (x1, x2), max (y1, y2))
to use this thing can maintain the current maximum range, then the history of the maximum value can also be used in the same way, but can not directly covered and is it can take max

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define N 100005
 4 #define oo 0x3f3f3f3f
 5 #define L (k<<1)
 6 #define R (L+1)
 7 #define mid (l+r>>1)
 8 struct ji{
 9     int a,b;
10 }laz[N<<2],f[N<<2];
11 int n,m,x,y,z,mx[N<<2][2];
12 char s[11];
13 ji max(ji x,ji y){
14     return ji{max(x.a,y.a),max(x.b,y.b)};
15 }
16 ji jia(ji x,ji y){
17     return ji{max(-oo,x.a+y.a),max(x.b+y.a,y.b)};
18 }
19 int calc(ji x,int y){
20     return max(x.a+y,x.b);
21 }
22 void update(int k,ji a,ji b){
23     f[k]=max(f[k],jia(laz[k],b));
24     laz[k]=jia(laz[k],a);
25     mx[k][1]=max(mx[k][1],calc(b,mx[k][0]));
26     mx[k][0]=calc(a,mx[k][0]);
27 }
28 void up(int k){
29     mx[k][0]=max(mx[L][0],mx[R][0]);
30     mx[k][1]=max(mx[L][1],mx[R][1]);
31 }
32 void down(int k){
33     update(L,laz[k],f[k]);
34     update(R,laz[k],f[k]);
35     laz[k]=f[k]={0,-oo};
36 }
37 void build(int k,int l,int r){
38     laz[k]=f[k]=ji{0,-oo};
39     if (l==r){
40         scanf("%d",&mx[k][0]);
41         mx[k][1]=mx[k][0];
42         return;
43     }
44     build(L,l,mid);
45     build(R,mid+1,r);
46     up(k);
47 } 
48 void update(int k,int l,int r,int x,int y,ji z){
49     if ((l>y)||(x>r))return;
50     if ((x<=l)&&(r<=y)){
51         update(k,z,z);
52         return;
53     }
54     down(k);
55     update(L,l,mid,x,y,z);
56     update(R,mid+1,r,x,y,z);
57     up(k);
58 }
59 int query(int k,int l,int r,int x,int y,int z){
60     if ((l>y)||(x>r))return -oo;
61     if ((x<=l)&&(r<=y))return mx[k][z];
62     down(k);
63     return max(query(L,l,mid,x,y,z),query(R,mid+1,r,x,y,z));
64 }
65 int main(){
66     scanf("%d",&n);
67     build(1,1,n);
68     scanf("%d",&m);
69     for(int i=1;i<=m;i++){
70         scanf("%s%d%d",s,&x,&y);
71         if ((s[0]=='Q')||(s[0]=='A')){
72             printf("%d\n",query(1,1,n,x,y,s[0]=='A'));
73             continue;
74         }
75         scanf("%d",&z);
76         if (s[0]=='P')update(1,1,n,x,y,ji{z,-oo});
77         else update(1,1,n,x,y,ji{-oo,z});
78     }
79 }
View Code

 

Guess you like

Origin www.cnblogs.com/PYWBKTDA/p/11372469.html