求助爆零
查看原帖
求助爆零
133116
Xhesika_Frost楼主2021/9/26 15:21
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define int long long
using namespace std;
struct tr{
	int sum;
	int fir;
	int d;
}tr[400005];
int n,m;
int x;
int a,b,c,d;
void pushup(int ro,int l){
	
	if(tr[ro].d==0&&tr[ro].fir==0){
		return ;
	} 
//	cout<<"S"<<endl;
	tr[ro<<1].fir+=tr[ro].fir;
	tr[ro<<1].d+=tr[ro].d;
	tr[ro<<1|1].d+=tr[ro].d;
	tr[ro<<1|1].fir+=tr[ro].d*l+tr[ro].fir;
	tr[ro].d=tr[ro].fir=0;
} 
void add(int ro,int l,int r,int L,int R,int fi,int d){
//	cout<<l<<" A "<<r<< " "<<fi<<endl; 
	if(L<=l&&r<=R){
		if(l==r){
			tr[ro].sum+=fi;
		//	cout<<tr[ro].sum<<endl;
			return ;
		}else{
			tr[ro].fir+=fi;
			tr[ro].d+=d;
		}
		return ;
	}
	int mid=(l+r)>>1;
	pushup(ro,max((long long)0,mid-l+1));
	if(L<=mid){
		add(ro<<1,l,mid,L,R,fi,d);
	}
	if(R>mid) add(ro<<1|1,mid+1,r,L,R,fi+max((long long)0,mid-L+1)*d,d);
}
int query(int ro,int l,int r,int L,int R){
//	cout<<l<<" B "<<r<<endl;
	if(L<=l&&r<=R){
	//	cout<<tr[ro].sum<<endl;
		return tr[ro].sum;
	}
	int mid=(l+r)>>1;
	pushup(ro,max((long long)0,mid-l+1));
	if(L<=mid){
		return query(ro<<1,l,mid,L,R);
	}
	if(R>mid) return query(ro<<1|1,mid+1,r,L,R);
}
signed main(){
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;++i){
		scanf("%lld",&x);
	//	cout<<"S"<<endl;
		add(1,1,n,i,i,x,0);
	//	cout<<query(1,1,n,i,i)<<endl;;
	}
	for(int i=1;i<=m;++i){
		scanf("%lld",&x);
		if(x==1){
			scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
			add(1,1,n,a,b,c,d);
		}
		if(x==2){
			scanf("%d",&x);
			cout<<query(1,1,n,x,x)<<endl;
		}
	}
	return 0;
} 
2021/9/26 15:21
加载中...