/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 8ms 8.16 MiB
#2 Accepted 8ms 8.0 MiB
#3 Accepted 463ms 8.953 MiB
#4 Accepted 305ms 8.473 MiB
#5 Accepted 276ms 8.488 MiB
#6 Accepted 270ms 8.355 MiB
#7 Accepted 7ms 7.98 MiB
#8 Accepted 7ms 8.086 MiB
#9 Accepted 444ms 8.75 MiB
#10 Accepted 332ms 8.438 MiB

Code

#include <bits/stdc++.h>
#define ll long long
using namespace std;
#ifdef velox
#include "debug.h"
#else
#define debug(x...)
#endif

const ll N = 2e5+10;
vector<ll> tree(4*N),v(N);

void make(ll node,ll b,ll e){
    if(b == e){
        if(v[b] > v[b+1]) tree[node] = 1;
        else tree[node] = 0;
        return;
    }
    ll mid=(b+e)/2;
    ll l=(node*2);
    ll r=(node*2)+1;

    make(l,b,mid);
    make(r,mid+1,e);

    tree[node]=tree[l]+tree[r];
}


void update(ll node,ll b, ll e, ll in, ll val){

    if(in>e || in<b) return;
    if(b >= in && e <= in){
        if(v[in] > v[in+1]) tree[node] = 1;
        else tree[node] = 0;
        return;
    }

    ll mid=(b+e)/2;
    ll l=(node*2);
    ll r=(node*2)+1;
    update(l,b,mid,in,val);
    update(r,mid+1,e,in,val);

    tree[node]=tree[l]+tree[r];
}


ll query(ll node,ll b, ll e, ll i,ll j){
    
    if(i>e || j<b) return 0;
    if(i<=b && j>=e) return tree[node];

    ll mid=(b+e)/2;
    ll l=(node*2);
    ll r=(node*2)+1;

    return query(l,b,mid,i,j)+query(r,mid+1,e,i,j);
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    
    ll len; cin >> len;
    for(int x=1; x<=len; x++) cin >> v[x];

    len--;

    make(1,1,len);

    ll q; cin >> q;
    while(q--){
        ll op; cin >> op;
        if(op == 1){
            int l, r; cin >> l >> r;
            v[l] = r;
            update(1, 1, len, l-1, r);
            if(l <= len) update(1, 1, len, l, r);
        }
        else{
            int l, r, val; cin >> l >> r;
            if(l == r){
                cout << "YES" << endl;
                continue;
            }
            if(query(1, 1, len, l, r-1) == 0) cout << "YES" << endl;
            else cout << "NO" << endl;
        }
    }
    
    
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1085 Sorted or !Sorted
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-03 08:35:09
Judged At
2024-11-11 03:04:31
Judged By
Score
100
Total Time
463ms
Peak Memory
8.953 MiB