40pts求调教
查看原帖
40pts求调教
754502
_AyachiNene楼主2023/2/20 20:25
#include<bits/stdc++.h>
using namespace std;
struct node
{
	int l,r,val;
}a[114514*4+1];
int n,m,ans,k;
void tre(int l,int r,int root)
{
	a[root].l=l;
	a[root].r=r;
	if(l==r)
	{
		cin>>a[root].val;
		return;
	}
	int mid=(l+r)/2;
	tre(l,mid,root*2);
	tre(mid+1,r,root*2+1);
	a[root].val=a[root*2].val+a[root*2+1].val;
}
void ask(int x,int root)
{
	if(a[root].l==a[root].r)
	{
		k=a[root].val;
		return;
	}
	int mid=(a[root].l+a[root].r)/2;
	if(x<=mid)
		ask(x,root*2);
	else
		ask(x,root*2+1);
}
void sum(int x,int y,int root)
{
	if(a[root].l>=x&&a[root].r<=y&&a[root].l==a[root].r)
	{
		ans=max(ans,a[root].val);
		return;
	}
	int mid=(a[root].l+a[root].r)/2;
	if(x<=mid)
		sum(x,y,root*2);
	if(y>mid)
		sum(x,y,root*2+1);
}
void add(int x,int root,int y)
{
	if(a[root].l==a[root].r)
	{
		a[root].val=y;
		return;
	}
	int mid=(a[root].l+a[root].r)/2;
	if(x<=mid)
		add(x,root*2,y);
	else
		add(x,root*2+1,y);
	a[root].val=a[root*2].val+a[root*2+1].val;
}
int main()
{
	cin>>n>>m;
	tre(1,n,1);
	for(int i=1;i<=m;i++)
	{
		int x,y;
		char c;
		cin>>c>>x>>y;
		if(c=='Q')
		{
			ans=0;
			sum(x,y,1);
			cout<<ans<<endl;
		}
		else
		{
			int a,b;
			ask(x,1);
			a=k;
			ask(y,1);
			b=k;
			if(a<=b)
				add(x,1,b);
		}
	}
	return 0;
}
2023/2/20 20:25
加载中...