/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 5ms 7.969 MiB
#2 Accepted 6ms 8.168 MiB
#3 Accepted 429ms 8.953 MiB
#4 Accepted 349ms 8.48 MiB
#5 Accepted 301ms 8.488 MiB
#6 Accepted 299ms 8.453 MiB
#7 Accepted 6ms 8.078 MiB
#8 Wrong Answer 6ms 8.066 MiB
#9 Wrong Answer 391ms 8.789 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(l,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:32:49
Judged At
2024-11-11 03:04:32
Judged By
Score
70
Total Time
429ms
Peak Memory
8.953 MiB