This question, at first glance: plus range, the minimum range. This is not a segment tree bare title it?
See the data range n- ≤ . 5 0 0 0 0 0 0. Tr opened a minimum maintenance, laz maintenance plus
Then a calculation space is about 152 MB, finished, MLE .
Methods change it, but I wanted to write the segment tree, the tree line is written to make me happy, I changed tactics
Originally direct output tr [1] , I deleted Laz , let tr time plus maintenance, access to visit each leaf
Node, and decentralized way, the original value by n array of a size to maintain the value of the leaf node is
tr [k] + a [l ] This is not to solve the space problem yet, then just write a Change , Down and ask not to be lost
Code, also the slowest only 424ms
#include<iostream> #include<cstdio> #define lson k<<1,l,mid #define rson k<<1|1,mid+1,r #define ls k<<1 #define rs k<<1|1 #define mid ((l+r)>>1) using namespace std; const int maxn=5000005; int n,m,a[maxn]; int tr[maxn<<2]; inline int read(){ int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();} return s*w; } inline void down(int k){ tr[ls]+=tr[k];tr[rs]+=tr[k]; } void change(int k,int l,int r,int x,int y,int val){ if(l==x&&y==r){ tr[k]+=val; return ; } if(y<=mid)change(lson,x,y,val); else if(x>mid)change(rson,x,y,val); else change(lson,x,mid,val),change(rson,mid+1,y,val); } int ask(int k,int l,int r){ if(l==r){ return a[l]+tr[k]; } if(tr[k])down(k); return min(ask(lson),ask(rson)); } int main(){ n=read();m=read(); for(int i=1;i<=n;++i) a[i]=read(); int x,y,z; while(m--){ x=read();y=read();z=read(); change(1,1,n,x,y,z); } printf("%d",ask(1,1,n)); return 0; }