0分求助~
查看原帖
0分求助~
1359067
saam楼主2024/10/20 19:17

0分,TLE,求助~

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
using namespace std;
typedef long long ll;
int n,q;
vector <ll>a(200002),b(200002);
ll w;
struct f{
	int l,r,d;
	void input() {
		cin >> l >> r >> d;
	}
};
vector <f>qw(1000002);
signed main() {
//	freopen("wxyt.in","r",stdin);
//	freopen("wxyt.out","w",stdout);
	IOS;
	cin >> n >> q >> w;
	for(int i=1;i<=n;++i) cin >> a[i];
	for(int i=1;i<=q;++i) {
		ll cnt=0,jf=0,bria,wf=w;
		qw[i].input();
		for(int j=qw[i].l;j<=qw[i].r;++j) a[j]+=1ll*qw[i].d;
		copy(a.begin(),a.begin()+n+1,b.begin());
		while(wf>0) {
			wf-=b[(++jf%n==0 ? n : jf%n)];
			++bria;
			++cnt;
			if(bria == n) {
				for(int k=1;k<=n;++k) b[k]*=1ll*2;
				bria=0;
			}
		}
		cout << cnt-1 << '\n';
	}
	return 0;
}
2024/10/20 19:17
加载中...