帮我同学问的 (他比较社恐,不敢问,让我帮他问了哈哈哈)
这道题他用的是分块,样例过了,但是提交上去以后,#1∼4 \textup{ \textbf\textcolor{red}{WA}},后面的几个点全部 \textup{ \textbf\textcolor{purple}{TLE}},他调了一晚上没调出来,给他弄破防了
#include<bits/stdc++.h>
using namespace std;
int a[200010],tag[200010],b[200010],ans[200010],tail;
int main()
{
int n,m,w;
cin>>n>>m>>w;
int sq=sqrt(n);
for(int i=1;i<=n;++i) cin >> a[i];
for(int i=1;i<=n;++i){
b[i]=(i-1)/sq+1;
ans[b[i]]+=a[i];
}
for(int i=(b[n]-1)*sq+1;i<=n;++i) tail++;
for(int i=1;i<=m;++i){
int cnt=0,tot=0;
int l,r,d;
cin>>l>>r>>d;
for(int j=l;j<=min(r,b[l]*sq);++j){
ans[b[j]]-=a[j];
a[j]+=d;
ans[b[j]]+=a[j];
}
if(b[l]!=b[r]){
for(int j=(b[r]-1)*sq+1;j<=r;++j){
ans[b[j]]-=a[j];
a[j]+=d;
ans[b[j]]+=a[j];
}
}
for(int j=b[l]+1;j<=b[r]-1;++j){
ans[j]+=sq*d;
tag[j]+=d;
}
int w1=w;
int j=1;
int y=0,x=0;
while(w1>ans[j]*(pow(2,y))){
if(b[j]!=b[n]){
w1-=ans[j]*(pow(2,y));
cnt+=sq;
}else{
w1-=ans[j]*(pow(2,y));
cnt+=tail;
}
tot++;
//cout<<cnt<<" "<<w1<<' '<<ans[j]<<" "<<pow(2,y)<<endl;
j++;
j%=b[n]+1;
if(j==0){
j++;
y++;
x=1;
}
}
for(int k=(j-1)*sq-1;k<=j*sq;++k){
if(w1<=a[k]){
break;
}
w1-=a[k]*(pow(2,y))+tag[b[k]]*(pow(2,y));
cnt++;
}
cout<<cnt<<endl;
}
return 0;
}
(他说他的马蜂非常良好,非常适宜阅读)