一直不出结果,求调!!!
查看原帖
一直不出结果,求调!!!
681941
OIer_Hhy楼主2024/6/5 19:08
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+20;
int a[maxn],n,q,u,v,x,y,z,opt;
struct SegmentTree{
	struct Node{
		int l,r,num,tag;
	}tree[maxn*4];
	inline void push_up(int p){
		tree[p].num=tree[p<<1].num+tree[(p<<1)+1].num;
	}
	inline void build(int p,int l,int r){
		tree[p].tag=0;
		tree[p].l=l;tree[p].r=r;
		if(l==r){
			tree[p].num=a[l];
			return ;
		}
		int m=(l+r)>>1;
		build(p<<1,l,m);
		build((p<<1)+1,m+1,r);
		push_up(p);
	}
	inline void func(int p,int l,int r,int k){
		tree[p].tag+=k;
    	tree[p].num+=k*(r-l+1);
	}
	inline void push_down(int p,int l,int r){
		int m=(l+r)>>1;
		func(p<<1,l,m,tree[p].tag);
		func((p<<1)+1,m+1,r,tree[p].tag);
		tree[p].tag=0;
	} 
	inline void update(int p,int l,int r,int k){
		if(x<=l&&r<=y){
			tree[p].num+=k*(r-l+1);
			tree[p].tag+=k;
			return ;
		}
		push_down(p,l,r);
    	int m=(l+r)>>1;
    	if(x<=m)update(p<<1,l,m,k);
    	if(y>m) update((p<<1)+1,m+1,r,k);
    	push_up(p);
	}
	int query(int p,int l,int r){
		int res=0;
		if(u<=l&&r<=v)return tree[p].num;
	    int m=(l+r)>>1;
	    push_down(p,l,r);
	    if(u<=m)res+=query(p<<1,l,m);
	    if(v>m) res+=query((p<<1)+1,m+1,r);
	    return res;
	}
}ST;
signed main(){
	n=2;
	q=1;
	for(int i=1;i<=n;i++) cin>>a[i];
	ST.build(1,1,n);
	while(q--)
		cout<<ST.query(1,1,n)<<endl;
	return 0;
}

2024/6/5 19:08
加载中...