蒟蒻代码MLE0分求调
  • 板块P1531 I Hate It
  • 楼主osmanlin
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/8/29 11:31
  • 上次更新2023/11/3 00:33:48
查看原帖
蒟蒻代码MLE0分求调
668649
osmanlin楼主2023/8/29 11:31
#include<iostream>
#define int long long
using namespace std;
int n,m,a[200001],d[800001];
inline void build(int start,int end,int number)
{
	if(start==end)
	{
		d[number]=a[start];
		return;
	}
	int mid=start+(end-start)/2;
	build(start,mid,number*2);
	build(mid+1,end,number*2+1);
	d[number]=max(d[number*2],d[number*2+1]);
}
inline int getsum(int left,int right,int start,int end,int p)
{
	if(start>=left&&end<=right)
	{
		return d[p];
	}
	int mid=start+(end-start)/2;
	int sum=0;
	if(end>right)
	{
		sum=max(sum,getsum(left,right,start,mid,p*2));
	}
	if(start<left)
	{
		sum=max(sum,getsum(left,right,mid+1,end,p*2+1));
	}
	return sum;
}
inline void update(int left,int right,int start,int end,int p)
{
	if(start==end)
	{
		d[p]=max(d[p],right);
		return;
	}
	int mid=start+(end-start)/2;
	if(left<=mid)update(left,right,start,mid,p*2);
	else update(left,right,mid+1,end,p*2+1);
	d[p]=max(d[p*2],d[p*2+1]);
} 
signed main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	build(1,n,1);
	while(m--)
	{
		char ch;
		int x,y;
		cin>>ch>>x>>y;
		if(ch=='Q')
		{
			cout<<getsum(x,y,1,n,1)<<endl;
		}
		else
		{
			if(a[x]<y)
			{
				update(x,y,1,n,1);
			}
		}
	}
	return 0;
}
2023/8/29 11:31
加载中...