全RE,求调
查看原帖
全RE,求调
613957
M_I_H_O_Y_O楼主2024/10/21 20:09

本地运行样例1 2都过了,样例3不知道是死循环还是T了反正没结果,然而提交全RE

#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#define ll long long

using namespace std;
ll n,q,w;
ll a[200005];
ll l,r,d;
ll t,sum;
ll ans;
ll z;
ll m;
ll s;
int main(){
	freopen("wxyt3.in","r",stdin);
//	freopen("ans.out","w",stdout);
	scanf("%lld%lld%lld",&n,&q,&w);
//		puts("1");
	for(int i=1;i<=n;i++){
		scanf("%lld",a+i);
		sum+=a[i];
//		puts("a");
	}
	ll p=(w/sum)+(w%sum==0? 0:1);
	m=log(p);
	if(1<<m!=p)m++;
	sum=sum*((1<<m)-1);
	ans=m*n;
	while(sum<w){
//		printf("%lld ",sum);
		sum+=a[++t]*(1<<m);
		if(t==n){
			t=0;
			m++;
		}
		ans++;
	}
//	printf("%lld %lld %lld\n",sum,m,t);
//	puts("");
	while(q--){
		scanf("%lld%lld%lld",&l,&r,&d);
		z=(r-l+1)*d*((1<<m+1)-1);
		if(l<=t&&t<=r){
			z-=(r-t)*d*(1<<m);
		}
		if(t<l){
			z-=(r-l+1)*d*(1<<m);
		}
		while(sum+z>=w){
//			puts("1");
			if(t==0){
				t=n;
				m--;
			}
			sum-=a[t]*(1<<m);
			if(l<=t&&t<=r)z-=d*(1<<m);
			t--;
			s++;
		}
		sum+=z;
		printf("%lld\n",ans-s);
		for(int i=l;i<=r;i++){
			a[i]+=d;
		}
	}
	return 0;
}

思路类似讲评的做法,但是讲评没代码不知道咋改

2024/10/21 20:09
加载中...