/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 584ms 6.727 MiB
#4 Accepted 426ms 6.262 MiB
#5 Accepted 385ms 6.168 MiB
#6 Accepted 372ms 6.195 MiB
#7 Accepted 1ms 532.0 KiB
#8 Accepted 1ms 320.0 KiB
#9 Accepted 568ms 6.691 MiB
#10 Accepted 498ms 6.348 MiB

Code

#include <bits/stdc++.h>
using namespace std;

#define ll                      long long int
#define mx 200005
ll arr[mx];
ll Tree[mx * 3];

void init(int node, int b, int e){
    if(b == e){
        if(arr[b] > arr[b+1]) Tree[node] = 1;
        else Tree[node] = 0;
        return;
    }
    int left = node * 2;
    int right = node * 2 + 1;
    int mid = (b + e) / 2;
    init(left, b, mid);
    init(right, mid+1, e);
    Tree[node] = Tree[left] + Tree[right];
}

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

    int left = node * 2;
    int right = node * 2 + 1;
    int mid = (b + e) / 2;
    ll p1 = query(left, b, mid, i, j);
    ll p2 = query(right, mid+1, e, i, j);
    return p1 + p2;
}

void update(int node, int b, int e, int i, int newvalue){
    if(i > e || i < b) return;
    if(b >= i && e <= i){
        if(arr[i] > arr[i+1]) Tree[node] = 1;
        else Tree[node] = 0;
        return;
    }

    int left = node * 2;
    int right = node * 2 + 1;
    int mid = (b + e) / 2;
    update(left, b, mid, i, newvalue);
    update(right, mid+1, e, i, newvalue);
    Tree[node] = Tree[left] + Tree[right];
}

int main(){
    ll n, q; cin >> n;
    for(int i = 1; i <= n; i++) cin >> arr[i];
    n--;
    init(1, 1, n);
    cin >> q;
    while(q--){
        int qe; cin >> qe;
        if(qe == 1){
            int l, r; cin >> l >> r;
            arr[l] = r;
            update(1, 1, n, l-1, r);
            if(l <= n) update(1, 1, n, l, r);
        }
        else{
            int l, r, val; cin >> l >> r;
            if(l == r){
                cout << "YES\n";
                continue;
            }
            if(query(1, 1, n, l, r-1) == 0) cout << "YES\n";
            else cout << "NO\n";
        }
    }
}

Information

Submit By
Type
Submission
Problem
P1085 Sorted or !Sorted
Contest
Bangladesh 2.0
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-16 16:18:24
Judged At
2024-10-03 13:27:36
Judged By
Score
100
Total Time
584ms
Peak Memory
6.727 MiB