悬关,0分样例不过求调
查看原帖
悬关,0分样例不过求调
917683
rnf5114楼主2023/12/4 23:26
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,m,a[100010],s,awa=1,sum,ans;
int op,x,y,k;
struct node{
	int l,r,he,zuo,you,add;
}tree[400010];
int maketree(int l,int r,int dian){
	int mid=(l+r)/2;
	if(l>r)
		return 0;
	sum++;
	if(l==r){
		tree[dian].l=l;
		tree[dian].r=r;
		tree[dian].he=a[l];
		return a[l];
	}
	tree[dian].l=l;
	tree[dian].r=r;
	tree[dian].he=maketree(l,mid,2*dian)+maketree(mid+1,r,2*dian+1);
	return tree[dian].he;
}
void cao1(int dian){
	if(dian==0)
		return ;
	if(tree[dian].r<x||tree[dian].l>y)
		return ;
	else if(tree[dian].l>=x&&tree[dian].r<=y){
		tree[dian].add+=k;
		return ;
	}
	else{
		cao1(tree[dian].zuo);
		cao1(tree[dian].you);
	}
}
void cao2(int dian,int jia){
	if(dian==0||tree[dian].r<x||tree[dian].l>y)
		return ;
	else if(tree[dian].l>=x&&tree[dian].r<=y){
		ans+=tree[dian].he+jia;
		return ;
	}
	else{
		cao2(tree[dian].zuo,jia+tree[dian].add);
		cao2(tree[dian].you,jia+tree[dian].add);
	}
}
signed main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	maketree(awa,n,awa);
	for(int i=1;i<=sum;i++){
		if(tree[2*i].he)
			tree[i].zuo=2*i;
		if(tree[2*i+1].he)
			tree[i].you=2*i+1;
	}
	while(m--){
		cin>>op;
		if(op==1){
			cin>>x>>y>>k;
			cao1(1);
		}
		else{
			ans=0;
			cin>>x>>y;
			cao2(1,0);
			cout<<ans<<endl;
		}
	}
    return 0;
}


/*
       ┏┓   ┏┓
     ┏┛┻━━━┛┻┓
     ┃       ┃
     ┃   ━   ┃
     ┃ ┳┛ ┗┳ ┃
     ┃       ┃
     ┃   ┻   ┃
     ┃       ┃
     ┗━┓   ┏━┛Codes are far away from bugs with the animal protecting
         ┃   ┃    神兽保佑,代码无bug
         ┃   ┃
         ┃   ┗━━━┓
         ┃      ┣┓
         ┃     ┏┛
         ┗┓┓┏━┳┓┏┛
           ┃┫┫ ┃┫┫
           ┗┻┛ ┗┻┛     ○| ̄|_

*/

2023/12/4 23:26
加载中...