/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 12ms 27.902 MiB
#2 Wrong Answer 11ms 28.07 MiB
#3 Accepted 104ms 30.258 MiB
#4 Accepted 98ms 29.781 MiB
#5 Accepted 82ms 29.77 MiB
#6 Wrong Answer 81ms 29.77 MiB
#7 Accepted 12ms 28.074 MiB
#8 Wrong Answer 12ms 27.887 MiB
#9 Wrong Answer 120ms 30.02 MiB
#10 Wrong Answer 130ms 29.641 MiB

Code

/**
 *  written by Binoy Barman .
**/

#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
#define all(v) v.begin(), v.end()
#define Too_Many_Jobs int tts, tc = 1; cin >> tts; hell: while(tts--)
#define Dark_Lord_Binoy ios_base::sync_with_stdio(false); cin.tie(NULL);

#ifdef LOCAL
#include "unravel.hpp"
#else
#define dbg(...) 42
#endif
#define int long long

const int N = 3e5 + 9;

int a[N];
struct Node {
    int first, last;
    bool sorted;
    Node() {
        first = last = -1;
        sorted = true;
    }
};
struct SegmentTree {
    #define lc (n << 1)
    #define rc ((n << 1) | 1)
    vector<Node> t;
    SegmentTree() {
        t.resize(4 * N);
    }
    inline void pull(int n) {
        t[n].first = t[lc].first;
        t[n].last = t[rc].last;
        t[n].sorted = (t[lc].sorted && t[rc].sorted && t[lc].last <= t[rc].first);
    }
    void build(int n, int b, int e) {
        if (b == e) {
            t[n].first = a[b];
            t[n].last = a[b];
            t[n].sorted = true;
            return;
        }
        int mid = (b + e) >> 1;
        build(lc, b, mid);
        build(rc, mid + 1, e);
        pull(n);
    }
    void upd(int n, int b, int e, int i, int x) {
        if (b > i || e < i) return;
        if (b == e && b == i) {
            t[n].first = x;
            t[n].last = x;
            t[n].sorted = true;
            return;
        }
        int mid = (b + e) >> 1;
        upd(lc, b, mid, i, x);
        upd(rc, mid + 1, e, i, x);
        pull(n);
    }
    bool query(int n, int b, int e, int i, int j) {
        if (b > j || e < i) return true;
        if (b >= i && e <= j) return t[n].sorted;
        int mid = (b + e) >> 1;
        return (query(lc, b, mid, i, j) && query(rc, mid + 1, e, i, j));
    }
}t;

int32_t main() {
Dark_Lord_Binoy
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n, q;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    t.build(1, 1, n);
    cin >> q;
    while(q--) {
        int c, l, r;
        cin >> c >> l >> r;
        if(c == 1) {
            t.upd(1, 1, n, l, r);
        }
        else {
            cout << (t.query(1, 1, n, l, r) ? "YES" : "NO") << nl;
        }
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1085 Sorted or !Sorted
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-17 11:52:35
Judged At
2024-08-17 11:52:35
Judged By
Score
50
Total Time
130ms
Peak Memory
30.258 MiB