#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+6;
ll a[N],b[N],m[N],d[N],t[4000005];
inline void build(ll l,ll r,ll p)
{
if(l==r)
{
t[p]=a[l];
return ;
}
ll m=(l+r)/2;
build(l,m,2*p);
build(m+1,r,2*p+1);
t[p]=t[2*p]+t[2*p+1];
}
inline ll getsum(ll l,ll r,ll s,ll tt,ll p)
{
if(l<=s and r>=tt) return t[p];
ll mid=(s+tt)/2,sum=0;
if(m[p]!=1)
{
m[2*p]*=m[p],m[2*p+1]*=m[p];
t[2*p]*=m[p];
t[2*p+1]*=m[p];
m[p]=1;
}
if(d[p]!=1)
{
d[2*p]*=d[p],d[2*p+1]*=d[p];
t[2*p]/=d[p];
t[2*p+1]/=d[p];
d[p]=1;
}
if(b[p])
{
b[2*p]+=b[p],b[2*p+1]+=b[p];
t[2*p]+=b[p]*(mid-s+1),t[2*p+1]+=b[p]*(tt-s);
b[p]=0;
}
if(l<=mid) sum+=getsum(l,r,s,mid,2*p);
if(r>mid) sum+=getsum(l,r,mid+1,tt,2*p+1);
return sum;
}
inline void upset(ll l,ll r,ll c,ll s,ll tt,ll p)
{
if(l<=s and r>=tt)
{
b[p]+=c;
t[p]+=c*(tt-s+1);
return ;
}
ll m=(s+tt)/2;
if(b[p] and s!=tt)
{
b[2*p]+=b[p],b[2*p+1]+=b[p];
t[2*p]+=b[p]*(m-s+1),t[2*p+1]+=b[p]*(tt-m);
b[p]=0;
}
if(l<=m) upset(l,r,c,s,m,2*p);
if(r>m) upset(l,r,c,m+1,tt,2*p+1);
t[p]=t[2*p]+t[2*p+1];
}
inline void upm(ll l,ll r,ll c,ll s,ll tt,ll p)
{
if(l<=s and r>=tt)
{
m[p]*=c;
t[p]+=(t[p]*(c-1));
return ;
}
ll mid=(s+tt)/2;
if(m[p])
{
m[2*p]+=m[p],m[2*p+1]+=m[p];
t[2*p]+=(t[p]*(m[p]-1))*(mid-s+1);
t[2*p+1]+=(t[p]*(m[p]-1))*(tt-mid);
m[p]=0;
}
if(l<=mid) upm(l,r,c,s,mid,2*p);
if(r>mid) upm(l,r,c,mid+1,tt,2*p+1);
t[p]=t[2*p]+t[2*p+1];
}
inline void div(ll l,ll r,ll c,ll s,ll tt,ll p)
{
if(l<=s and r>=tt)
{
d[p]*=c;
t[p]/=c;
return ;
}
}
inline ll liyijie(ll xue,ll r)
{
ll l=1,ans,n1=r;
while(l<=r)
{
ll mid=(l+r)/2;
//cout<<mid<<" "<<getsum(1,mid,1,n1,1)<<" "<<xue<<endl;
if(getsum(1,mid,1,n1,1)>=xue)
{
ans=mid;
r=mid-1;
}
else l=mid+1;
}
return ans-1;
}
int main()
{
ll n,q,w;
cin>>n>>q>>w;
for(int i=1;i<=4*n;i++) m[i]=1,d[i]=1;
for(int i=1;i<=n;i++) cin>>a[i];
build(1,n,1);
while(q--)
{
ll l1,l2,l3;
cin>>l1>>l2>>l3;
//cout<<getsum(1,n,1,n,1)<<endl;
upset(l1,l2,l3,1,n,1);
ll pur=getsum(1,n,1,n,1),ans=0,ti,flag=0;
//cout<<pur<<endl;
if(w>pur)
{
flag=1;
if(w%pur!=0) w+=pur;
ti=log2(w/pur);
ans+=n*ti;
w-=pur*((1<<ti)-1);
pur*=(1<<ti);
upm(1,n,1<<ti,1,n,1);
}
//cout<<getsum(1,n,1,n,1)<<endl;
ans+=liyijie(w,n);
cout<<ans<<endl;
if(flag) div(1,n,1<<ti,1,n,1);
}
return 0;
}
感谢