全 RE 请求 DEBUG
查看原帖
全 RE 请求 DEBUG
922691
Hisy楼主2024/6/15 10:42
#include<cstdio>
#define int long long
struct node{
	int sum,tag;
};
node tree[100001<<2];
int diff[100001];
inline void push_up(int root){
	tree[root].sum=tree[root<<1].sum+tree[root<<1|1].sum;
};
inline void push_down(int root,int first,int last){
	int middle=first+last>>1;
	tree[root<<1].tag+=tree[root].tag;
	tree[root<<1|1].tag+=tree[root].tag;
	tree[root<<1].sum+=tree[root].tag*(middle-first+1);
	tree[root<<1|1].sum+=tree[root].tag*(last-middle);
	tree[root].tag=0;
};
inline void build(int root,int first,int last){
	tree[root].tag=0;
	int middle=first+last>>1;
	if(first==last){
		tree[root].sum=diff[first];
		return;
	};
	build(root<<1,first,middle);
	build(root<<1|1,middle+1,last);
	push_up(root);
};
inline void change(int root,int first,int last,int low,int high,int addtag){
	if(low<=first&&last<=high){
		tree[root].tag+=addtag;
		tree[root].sum+=(last-first+1)*addtag;
		return; 
	};
	int middle=first+last>>1;
	push_down(root,first,last);
	if(low<=middle){
		change(root<<1,first,middle,low,high,addtag);
	};
	if(middle>high){
		change(root<<1|1,middle+1,last,low,high,addtag);
	};
	push_up(root);
	return;
};
inline int query(int root,int first,int last,int low,int high){
	if(low<=first&&last<=high){
		return tree[root].sum;
	};
	int middle=first+last>>1,result=0;
	push_down(root,first,last);
	if(low<=middle){
		result+=query(root<<1,first,middle,low,high);
	};
	if(middle>high){
		result+=query(root<<1|1,middle+1,last,low,high);
	};
	return result;
};
signed main(signed argc,char **argv){
	int size,operate;
	scanf("%lld %lld",&size,&operate);
	for(int iter=1;iter<=size;++iter){
		scanf("%lld",&diff[iter]);
	};
	for(int iter=size-1;iter>=1;--iter){
		diff[iter+1]=diff[iter+1]-diff[iter];
	};
	build(1,1,size);
	do{
		int symbol;
		scanf("%lld",&symbol);
		if(symbol==1){
			int low,high,addtag,multag;
			scanf("%lld %lld %lld %lld",&low,&high,&addtag,&multag);
			change(1,1,size,low,low,addtag);
			if(low+1<=high){
				change(1,1,size,low+1,high,multag);
			};
			if(high<size){
				change(1,1,size,high+1,high+1,-(addtag+multag*(high-low)));
			};
		}else{
			int point;
			scanf("%lld",&point);
			printf("%lld\n",query(1,1,size,1,point));
		};
	}while(--operate);
	return 0;
};
2024/6/15 10:42
加载中...