全RE求助
查看原帖
全RE求助
356925
快斗游鹿楼主2022/6/11 10:05

样例过了,但全部RE。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=200010;
struct tree{
	ll l;
	ll r;
	ll ans;
	ll add;
}t[N*4];
ll n,f;
ll a[N];
void build(ll p,ll l,ll r){
	t[p].l=l;t[p].r=r;
	if(l==r){
		t[p].ans=a[l];
		return;
	}
	ll mid=(l+r)>>1;
	build(p*2,l,mid);
	build(p*2+1,mid+1,r);
	t[p].ans=t[p*2].ans+t[p*2+1].ans;
}
void spread(ll p){
	if(t[p].add){
		t[p*2].ans+=t[p].add*(t[p*2].r-t[p*2].l+1);
		t[p*2].add+=t[p].add;
		t[p*2+1].ans+=t[p].add*(t[p*2+1].r-t[p*2+1].l+1);
		t[p*2+1].add+=t[p].add;
		t[p].add=0;
	}
}
void change(ll p,ll l,ll r,ll k){
	if(l<=t[p].l&&t[p].r<=r){
		t[p].ans+=k*(t[p].r-t[p].l+1);
		t[p].add+=k;
		return;
	}
	spread(p);
	ll mid=(t[p].l+t[p].r)>>1;
	if(l<=mid)change(p*2,l,r,k);
	if(r>mid)change(p*2,l,r,k);
	t[p].ans=t[p*2].ans+t[p*2+1].ans;
}
ll ask(ll p,ll l,ll r){
	if(l<=t[p].l&&t[p].r<=r){
		return t[p].ans;
	}
	spread(p);
	ll mid=(t[p].l+t[p].r)>>1;
	ll val=0;
	if(l<=mid)val+=ask(p*2,l,r);
	if(r>mid)val+=ask(p*2+1,l,r);
	return val;
}
int main(){
	scanf("%lld%lld",&n,&f);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	build(1,1,n);
	for(int i=1;i<=f;i++){
		ll x;scanf("%lld",&x);
		if(x==1){
			ll lll,rr,kk;scanf("%lld%lld%lld",&lll,&rr,&kk);
			change(1,lll,rr,kk);
		}
		else if(x==2){
			ll kk;scanf("%lld",&kk);
			change(1,1,1,kk);
		}
		else if(x==3){
			ll kk;scanf("%lld",&kk);
			change(1,1,1,-kk);
		}
		else if(x==4){
			ll lll,rr;scanf("%lld%lld",&lll,&rr);
			printf("%lld\n",ask(1,lll,rr));
		}
		else if(x==5){
			printf("%lld\n",ask(1,1,1));
		}
	}
	return 0;
}

2022/6/11 10:05
加载中...