1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
| #include<algorithm> #include<iostream> #include<iomanip> #include<cstring> #include<cstdlib> #include<climits> #include<vector> #include<cstdio> #include<cmath> #include<queue> using namespace std;
typedef long long LL; #define inf LLONG_MAX/3
inline const int Get_Int() { int num=0,bj=1; char x=getchar(); while(x<'0'||x>'9') { if(x=='-')bj=-1; x=getchar(); } while(x>='0'&&x<='9') { num=num*10+x-'0'; x=getchar(); } return num*bj; }
const int maxn=500005;
struct Data { LL a,b; Data(LL _a=0,LL _b=-inf):a(_a),b(_b) {} Data operator + (const Data& y) { return Data(max(-inf,a+y.a),max(b+y.a,y.b)); } };
Data max(Data x,Data y) { return Data(max(x.a,y.a),max(x.b,y.b)); }
struct Tree { int left,right; Data now,history; Tree(int l=0,int r=0,Data v=Data(),Data his=Data()):left(l),right(r),now(v),history(his) {} };
struct Segment_Tree { Tree tree[maxn*4]; #define ls index<<1 #define rs index<<1|1 void build(int index,int Left,int Right,int* a) { tree[index]=Tree(Left,Right); if(Left==Right) { tree[index].now=tree[index].history=Data(a[Left],a[Left]); return; } int mid=(Left+Right)>>1; build(ls,Left,mid,a); build(rs,mid+1,Right,a); } void push_down(int index) { tree[ls].history=max(tree[ls].history,tree[ls].now+tree[index].history); tree[ls].now=tree[ls].now+tree[index].now; tree[rs].history=max(tree[rs].history,tree[rs].now+tree[index].history); tree[rs].now=tree[rs].now+tree[index].now; tree[index].now=tree[index].history=Data(); } void modify(int index,int Left,int Right,Data v) { if(Left>tree[index].right||Right<tree[index].left)return; if(Left<=tree[index].left&&Right>=tree[index].right) { tree[index].now=tree[index].now+v; tree[index].history=max(tree[index].history,tree[index].now); return; } push_down(index); modify(ls,Left,Right,v); modify(rs,Left,Right,v); } Data query(int index,int target,bool flag) { if(target>tree[index].right||target<tree[index].left)return Data(); if(tree[index].left==tree[index].right)return flag?tree[index].now:tree[index].history; push_down(index); return query(ls,target,flag)+query(rs,target,flag); } } st;
int n,m,a[maxn];
int main() { n=Get_Int(); m=Get_Int(); for(int i=1; i<=n; i++)a[i]=Get_Int(); st.build(1,1,n,a); for(int i=1; i<=m; i++) { int opt=Get_Int(); if(opt==1) { int l=Get_Int(),r=Get_Int(),x=Get_Int(); st.modify(1,l,r,Data(x,-inf)); } else if(opt==2) { int l=Get_Int(),r=Get_Int(),x=Get_Int(); st.modify(1,l,r,Data(-x,0)); } else if(opt==3) { int l=Get_Int(),r=Get_Int(),x=Get_Int(); st.modify(1,l,r,Data(-inf,x)); } else if(opt==4) { Data x=st.query(1,Get_Int(),1); printf("%lld\n",max(x.a,x.b)); } else { Data x=st.query(1,Get_Int(),0); printf("%lld\n",max(x.a,x.b)); } } return 0; }
|