保龄求助!
查看原帖
保龄求助!
178131
郁逸丶楼主2020/9/22 22:32
#include<iostream>
#include<cmath>
#define ll long long 
using namespace std;
const int N=1e7+5;
ll a[N],n,m,k,o,j,q,w;
struct tree{ll l,r,pre,maxn;}t[N];
void update(ll p)
{
	t[p].pre=t[p<<1].pre+t[p<<1|1].pre;
	t[p].maxn=max(t[p<<1].maxn,t[p<<1|1].maxn);
}
void change(ll p,ll x,ll y)
{
	if(y<q||w<x) return ; 

	if(t[p].l==t[p].r) 
	{
		t[p].pre=sqrt(t[p].pre);
		t[p].maxn=sqrt(t[p].maxn);
		return ;
	}
	ll mid=(t[p].l+t[p].r)>>1;
	if(x<=mid&&t[p<<1].maxn>1) change(p<<1,x,mid);
	if(y>mid&&t[p<<1|1].maxn>1) change(p<<1|1,mid+1,y);
	update(p);
}
void build(ll p,ll l,ll r)
{
	t[p].l=l;t[p].r=r;
	if(l==r)
	{
		t[p].maxn=t[p].pre=a[l];
		return ;
	}
	ll mid=(l+r)>>1;
	build(p<<1,l,mid);
	build(p<<1|1,mid+1,r);
	update(p);
}
ll ask(ll p,ll x,ll y)
{
	ll ans=0;
	
	if(x<=t[p].l&&y>=t[p].r) return t[p].pre;
	
	ll mid=t[p].l+t[p].r>>1;
	if(x<=mid) ans+=ask(p*2,x,mid);
	if(y>mid) ans+=ask(p*2|1,mid+1,y);
	return ans;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	build(1,1,n);

	cin>>m;
	for(int i=1;i<=m;i++)
	{
		ll k,l,r;
		cin>>k>>l>>r;
		if(l>r) swap(l,r); 
		if(k==0)
		{
			q=l;w=r;
			change(1,l,r);	
		}
		else
		{
			cout<<ask(1,l,r)<<endl;
		} 
	}
}
2020/9/22 22:32
加载中...