样例过了,全WA
  • 板块P1531 I Hate It
  • 楼主lyhqwq
  • 当前回复0
  • 已保存回复0
  • 发布时间2021/5/10 19:46
  • 上次更新2023/11/4 23:25:42
查看原帖
样例过了,全WA
100690
lyhqwq楼主2021/5/10 19:46
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define il inline
#define int long long
const int MAXN=2*1e5+5;
using namespace std;
int tree[MAXN<<2],a[MAXN];
char c;
int n,m;
il int read(){
	register int x=0,f=1;
	register char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
int lc(int rt){
	return (rt<<1);
}
int rc(int rt){
	return (rt<<1|1);
}
void pushup(int rt){
	tree[rt]=max(tree[lc(rt)],tree[rc(rt)]);
}
void build(int l,int r,int rt){
	if(l==r){
		tree[rt]=a[l];
		return;
	}
	int m=(l+r)>>1;
	build(l,m,lc(rt));
	build(m+1,r,rc(rt));
	pushup(rt);
}
void upd(int x,int y,int l,int r,int rt){
	if(l==r){
		if(tree[rt]<y) tree[rt]=y;
		return;
	}
	int m=(l+r)>>1;
	if(x<=m) upd(x,y,l,m,lc(rt));
	else upd(x,y,m+1,r,rc(rt));
	pushup(rt);
}
int query(int L,int R,int l,int r,int rt){
	if(L<=l&&R>=r){
		return tree[rt];
	}
	int m=(l+r)>>1;
	int ans=-1e9;
	if(L<=m) ans=max(ans,query(L,R,l,m,lc(rt)));
	if(R>m) ans=max(ans,query(L,R,m+1,r,rc(rt)));
	return ans;
}
signed main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read();
	m=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
	}
	build(1,n,1);
	for(int i=1;i<=m;i++){
		int x,y;
		scanf("%c",&c);
		x=read();
		y=read();
		switch(c){
			case 'Q':{
				cout<<query(x,y,1,n,1)<<endl;
				break;
			}
			case 'U':{
				upd(x,y,1,n,1);
				break;
			}
		}
	}
	return 0;
}

2021/5/10 19:46
加载中...