样例没过求调
查看原帖
样例没过求调
738882
OIer_dcy__AK_IOI楼主2024/11/30 20:52

样例没过求调

输出:

5
4
5
5
//单点修改&&区间查询(最大值)
#include<bits/stdc++.h>

using namespace std;

#define int long long

const int maxn=2e5+10;
const int maxm=8e5+10;

int n,m;
int a[maxn];
struct Tree{
    int mx;
    int left,right;
}tree[maxm];

inline void build(int root,int l,int r){
    tree[root].left=l;
    tree[root].right=r;
    if(tree[root].left==tree[root].right){
        tree[root].mx=a[tree[root].left];
        return;
    }
    int mid=(tree[root].left+tree[root].right-1)>>1;
    build(root<<1,l,mid);
    build(root<<1|1,mid+1,r);
    tree[root].mx=max(tree[root<<1].mx,tree[root<<1|1].mx);
}

inline void update(int root,int p,int x){
    if(tree[root].left==tree[root].right){
        tree[root].mx=x;
        return;
    }
    int mid=(tree[root].left+tree[root].right)>>1;
    if(p<=mid) update(root<<1,p,x);
    else update(root<<1|1,p,x);
    tree[root].mx=max(tree[root<<1].mx,tree[root<<1|1].mx);
}

inline int query(int root,int l,int r){
    int res=-0x3f3f3f3f;
    if(l<=tree[root].left&&r>=tree[root].right){
        return tree[root].mx;
    }
    int mid=(tree[root].left+tree[root].right-1)>>1;
    if(l<=mid) res=max(res,query(root<<1,l,r));
    if(r>mid) res=max(res,query(root<<1|1,l,r));
    return res;
}

signed main(){
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    build(1,1,n);
    while(m--){
        int a,b;
        char op;
        cin>>op>>a>>b;
        if(op=='Q'){
            printf("%lld\n",query(1,a,b));
        }
        if(op=='C'){
            if(query(1,a,a)<b) update(1,a,b);
        }
    }
    return 0;
}
2024/11/30 20:52
加载中...