#include #include #include #include #include #include #include #include #include #define MOD 1000000007 #define mkp make_pair typedef long long ll; using namespace std; class LazySegmentTree{ private: int n; vector node,lazy; public: LazySegmentTree(vector v){ n=1; while(n=0;i--) node[i]=node[2*i+1]+node[2*i+2]; } void eval(int k,int l,int r){ if(lazy[k]!=0){ node[k]+=lazy[k]; if(r-l>1){ lazy[2*k+1]+=lazy[k]/2; lazy[2*k+2]+=lazy[k]/2; } lazy[k]=0; } } void add(int a,int b,ll x,int k=0,int l=0,int r=-1){ if(r<0) r=n; eval(k,l,r); if(b<=l||r<=a) return; if(a<=l&&r<=b){ lazy[k]+=(r-l)*x; eval(k,l,r); }else{ add(a,b,x,2*k+1,l,(r+l)/2); add(a,b,x,2*k+2,(r+l)/2,r); node[k]=node[2*k+1]+node[2*k+2]; } } ll getSum(int a,int b,int k=0,int l=0,int r=-1){ if(r<0) r=n; eval(k,l,r); if(b<=l||r<=a) return 0; if(a<=l&&r<=b) return node[k]; ll vl,vr; vl=getSum(a,b,2*k+1,l,(l+r)/2); vr=getSum(a,b,2*k+2,(l+r)/2,r); return vl+vr; } }; int N,Q; vector A; int L=24; int main(){ cin>>N; A.resize(N); for(int i=0;i>A[i]; LazySegmentTree seg(A); ll ans=0; for(int i=0;i+L-1>Q; for(int i=0;i>t>>v; t--; ll val=seg.getSum(t,t+1,0,0,-1); seg.add(t,t+1,v-val); for(int j=0;j=0&&t-j+L-1