50pts求助
查看原帖
50pts求助
688596
dayz_break404楼主2023/4/12 17:43
#include<bits/stdc++.h>
using namespace std; 
#define ll long long
#define maxn 100020
ll n,m,a[maxn];
struct node{
	int maxx,vis;
}tree[maxn<<2];
inline ll ls(ll x){
	return x<<1;
}
inline ll rs(ll x){
	return x<<1|1;
}
inline void push_up(ll x){
	tree[x].maxx=max(tree[ls(x)].maxx,tree[rs(x)].maxx);
	tree[x].vis=tree[ls(x)].vis+tree[rs(x)].vis;
}
inline void build(ll p,ll l,ll r){
	if(l==r){
		tree[p].maxx=tree[p].vis=a[l];
		return ;
	}
	ll mid=(l+r)>>1;
	build(ls(p),l,mid);
	build(rs(p),mid+1,r);
	push_up(p);
}
void update(ll p,ll l,ll r,ll x,ll y){
	if(l==r&&l>=x&&r<=y){
		tree[p].vis=sqrt(tree[p].vis);
		tree[p].maxx=tree[p].vis;
		return ;
	}
	ll mid=(l+r)>>1;
	if(tree[ls(p)].maxx>1&&mid>=x) update(ls(p),l,mid,x,y);
	if(tree[rs(p)].maxx>1&&mid<y) update(rs(p),mid+1,r,x,y);
	push_up(p);
}
ll query(ll p,ll l,ll r,ll x,ll y){
	ll res=0;
	if(l>=x&&r<=y){
		return tree[p].vis;
	}
	ll mid=(l+r)>>1;
	if(x<=mid) res+=query(ls(p),l,mid,x,y);
	if(mid<y) res+=query(rs(p),mid+1,r,x,y);
	return res;
}
int main(){
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	ll op,u,v;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	build(1,1,n);
	scanf("%lld",&m);
	for(int i=1;i<=m;i++){
		scanf("%lld%lld%lld",&op,&u,&v);
		if(u>v) swap(u,v);
		if(op==0){
			update(1,1,n,u,v);
		}
		else if(op){
			printf("%lld\n",query(1,1,n,u,v));
		}
	}	
	return 0;
}
2023/4/12 17:43
加载中...