/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 8ms 8.16 MiB
#2 Accepted 8ms 8.066 MiB
#3 Accepted 460ms 8.949 MiB
#4 Accepted 312ms 8.309 MiB
#5 Accepted 272ms 8.445 MiB
#6 Accepted 270ms 8.469 MiB
#7 Accepted 7ms 8.121 MiB
#8 Accepted 7ms 8.141 MiB
#9 Accepted 452ms 8.805 MiB
#10 Accepted 325ms 8.477 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-10-03 13:12:21
Judged By
Score
100
Total Time
460ms
Peak Memory
8.949 MiB