比赛 2025.3.6 评测结果 AAAAAAAAAA
题目名称 WHZ 的序列 最终得分 100
用户昵称 徐诗畅 运行时间 2.458 s
代码语言 C++ 内存使用 15.45 MiB
提交时间 2025-03-06 19:37:01
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+5;
int n,a[N],m,b[N];
struct tree{
	int t[N<<2],tag[N<<2],s[N];
	void push_up(int p){t[p]=t[p<<1]+t[p<<1|1];}
	void build(int p,int l,int r){
		t[p]=tag[p]=0;
		if(l==r){
			t[p]=s[l];
			return;
		}
		int mid=(l+r)>>1;
		build(p<<1,l,mid);
		build(p<<1|1,mid+1,r);
		push_up(p);
	}
	void addtag(int p,int l,int r,int d){
		t[p]+=(r-l+1)*d;
		tag[p]+=d;
	}
	void push_down(int p,int l,int r){
		if(tag[p]){
			int mid=(l+r)>>1;
			addtag(p<<1,l,mid,tag[p]);
			addtag(p<<1|1,mid+1,r,tag[p]);
			tag[p]=0;
		}
	}
	void update(int p,int l,int r,int L,int R,int d){
		if(L<=l&&R>=r){
			addtag(p,l,r,d);
			return;
		}
		int mid=(l+r)>>1;
		push_down(p,l,r);
		if(L<=mid) update(p<<1,l,mid,L,R,d);
		if(R>mid) update(p<<1|1,mid+1,r,L,R,d);
		push_up(p);
	}
	int query(int p,int l,int r,int L,int R){
		if(L<=l&&R>=r) return t[p];
		int mid=(l+r)>>1;
		push_down(p,l,r);
		int ans=0;
		if(L<=mid) ans+=query(p<<1,l,mid,L,R);
		if(R>mid) ans+=query(p<<1|1,mid+1,r,L,R);
		return ans;
	}
}tr[2];
signed main(){
	freopen("whz_sequence.in","r",stdin);
	freopen("whz_sequence.out","w",stdout);
	scanf("%lld",&n);
	for(int i = 1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	int p1=0,p2=0;
	for(int i = 1;i<=n;i+=2) tr[0].s[++p1]=a[i];
	for(int i = 2;i<=n;i+=2) tr[1].s[++p2]=a[i];
	tr[0].build(1,1,n); tr[1].build(1,1,n);
	scanf("%lld",&m);
	while(m--){
		int op,l,r,d; cin>>op;
		if(op==1){
			scanf("%lld%lld%lld",&l,&r,&d);
			if(l%2==1){
				tr[0].update(1,1,n,(l+1)/2,(r+1)/2,d);
				tr[1].update(1,1,n,(l+1)/2,r/2,d);
			}
			else{
				tr[0].update(1,1,n,(l+2)/2,(r+1)/2,d);
				tr[1].update(1,1,n,l/2,r/2,d);
			}
		}
		else{
			scanf("%lld%lld",&l,&r); int ans;
			if(l%2==1) ans=tr[0].query(1,1,n,(l+1)/2,(r+1)/2)-tr[1].query(1,1,n,(l+1)/2,r/2);
			else ans=-tr[0].query(1,1,n,(l+2)/2,(r+1)/2)+tr[1].query(1,1,n,l/2,r/2);
			printf("%lld\n",ans);
		}
	}
	return 0;
}