Difference thought: Consider [l,r] borrowed D classroom, then let S[l]+=d,s[r+1]-=d, then the s to ask the prefix and, is the case of the day, you can judge whether to exceed.
Then you can have two points.
Segment tree up to 95 23333333 ...
In fact, the Huang long code copy ... Don't want to write it.
#include <iostream>#include<cstdio>#include<cstring>using namespacestd;intn,m,ans,a[1000010],d[1000010],x[1000010],y[1000010],s[1000010],sum;template<classT> TGet(T &u) {CharX for(;! IsDigit (x=GetChar ());); for(u=x- -; IsDigit (X=getchar ()); u*=Ten, u+= (X- -) ); ungetc (X,stdin);returnu;}BOOLJudgeintv) {memset (s),0,sizeof(s)); sum=0; for(intI=1; i<=v;i++) {S[x[i]]+=d[i];s[y[i]+1]-=d[i];} for(intI=1; i<=n;i++) {sum+=S[i]; if(Sum>a[i])return 0; } return 1;}intMain () {Get(n),Get(m); for(intI=1; i<=n;i++)Get(A[i]); for(intI=1; i<=m;i++) Get(D[i]),Get(X[i]),Get(Y[i]); intL=1, r=m; while(l<=r) {intMid= (l+r) >>1; if(!judge (mid)) {ans=mid;r=mid-1;} ElseL=mid+1; } if(!ans) printf ("0"); Elseprintf"-1\n%d\n", ans); return 0;}
Codevs 1217 borrowing the classroom