NirvanaCeleste @ 2024-07-17 19:08:31
#include <bits/stdc++.h>
using namespace std;
inline void read(int& qin){
int qout = 0, w = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
if(ch == '-') w = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
qout = qout * 10 + ch - '0';
ch = getchar();
}
qin = qout * w;
}
inline void write(int x){
if(x < 0) putchar('-'),x = -x;
if(x > 9) write(x/10);
putchar(x % 10 + '0');
}
int n,m;
int now[500050],t[500050 * 4];
inline int ls(int p){return p<<1;}
inline int rs(int p){return p<<1|1;}
void push_up(int p) {t[p] = max(t[ls(p)],t[rs(p)]);}
void build(int p,int l,int r){
if(l == r){
t[p] = now[l];
return;
}
int mid = (l + r) >> 1;
build(ls(p),l,mid);
build(rs(p),mid+1,r);
push_up(p);
}
void move(int p,int l,int r,int cnt,int op){
if(l == r){
t[p] = cnt;
return;
}
int mid = (l + r) >> 1;
if(op <= mid) move(ls(p),l,mid,cnt,op);
else move(rs(p),mid+1,r,cnt,op);
push_up(p);
}
int check(int lc,int rc,int p,int l,int r){
int res = INT_MIN;
if(lc <= l && r <= rc) return t[p];
int mid = (l + r) >> 1;
if(lc <= mid) res = max(res,check(lc,rc,ls(p),l,mid));
if(rc > mid) res = max(res,check(lc,rc,rs(p),mid+1,r));
return res;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++) read(now[i]);
build(1,1,n);
int k,a,b,l,r;
for(int i=1;i<=m;i++){
read(k),read(a),read(b);
if(k == 1){
l = min(a,b),r = max(a,b);
write(check(l,r,1,1,n));
putchar('\n');
}
else move(1,1,n,b,a);
}
return 0;
}
by xiao7_Mr_10_ @ 2024-07-18 08:33:44
我很好奇你这个为什么能有9分而不是0分
by NirvanaCeleste @ 2024-07-18 11:41:33
@xiao7_Mr10 但是WA9个点,按照这样写不应该是TLE吗(至少应该输出正确答案)?
by xiao7_Mr_10_ @ 2024-07-18 11:48:14
@NirvanaCeleste 你的算法有问题,最大字段和不一定只有一个数组成,可能是一堆数,自己看题解
by NirvanaCeleste @ 2024-07-18 11:57:12
@xiao7_Mr10 我去,谢谢大佬,突然发现我写的是单个数的最大值