【洛谷】P1531 I Hate It

板子题

ACcode:

#include
using namespace std;
const int N = 2e5+10;
typedef long long ll;
int n,m,w[N];
struct node{
    int l,r;
    ll maxv;
}tr[N*4];
void pushup(int u){
    tr[u].maxv=max(tr[u<<1].maxv,tr[u<<1|1].maxv);
}
void build(int u,int l,int r){
    if(l==r)tr[u]={l,r,w[l]};
    else{
        tr[u]={l,r};
        int mid=l+r>>1;
        build(u<<1,l,mid),build(u<<1|1,mid+1,r);
        pushup(u);
    }
}
ll query(int u,int l,int r){
    if(l<=tr[u].l&&tr[u].r<=r)return tr[u].maxv;
    ll max1=0;
    int mid=tr[u].l+tr[u].r>>1;
    if(l<=mid)max1=query(u<<1,l,r);
    if(mid>1;
        if(x<=mid)modify(u<<1,x,v);
        else modify(u<<1|1,x,v);
        pushup(u);
    }
}
signed main(){
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>w[i];
    build(1,1,n);
    while(m--){
        string op;
        int a,b;
        cin>>op>>a>>b;
        if(op=="U"){
            if(w[a]

over~

你可能感兴趣的:(算法,c++,树状数组)