/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 18ms 19.875 MiB
#2 Wrong Answer 18ms 19.969 MiB
#3 Accepted 125ms 22.316 MiB
#4 Accepted 119ms 21.797 MiB
#5 Accepted 92ms 21.617 MiB
#6 Wrong Answer 92ms 21.797 MiB
#7 Accepted 18ms 19.973 MiB
#8 Wrong Answer 18ms 19.898 MiB
#9 Wrong Answer 130ms 22.195 MiB
#10 Wrong Answer 146ms 21.77 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 SegmentTree {
    int f[4 * N], s[4 * N];
    bool ok[4 * N];
    SegmentTree() {
        for (int i = 0; i < 4 * N; i++) {
            f[i] = s[i] = 0;
            ok[i] = false;
        }
    }
    void build(int n, int b, int e) {
        if (b == e) {
            f[n] = a[b];
            s[n] = a[b];
            ok[n] = true;
            return;
        }
        int mid = (b + e) / 2, l = n * 2, r = l + 1;
        build(l, b, mid);
        build(r, mid + 1, e);
        f[n] = f[l];
        s[n] = s[r];
        ok[n] = false;
        if(ok[l] && ok[r] && (s[l] <= f[r])) ok[n] = true;
        dbg(b, e, f[n], s[n], ok[n]);
    }
    void upd(int n, int b, int e, int i, int x) {
        if (b > i || e < i) return;
        if (b == e && b == i) {
            f[n] = x; 
            s[n] = x; 
            ok[n] = true; 
            return;
        }
        int mid = (b + e) / 2, l = n * 2, r = l + 1;
        upd(l, b, mid, i, x);
        upd(r, mid + 1, e, i, x);
        f[n] = f[l];
        s[n] = s[r];
        ok[n] = false;
        if(ok[l] && ok[r] && (s[l] <= f[r])) ok[n] = true;
        dbg(b, e, f[n], s[n], ok[n]);
    }
    bool query(int n, int b, int e, int i, int j) {
        if (b > j || e < i) return true; // return approriate value
        if (b >= i && e <= j) return ok[n];
        int mid = (b + e) / 2, l = n * 2, r = l + 1;
        return (query(l, b, mid, i, j) && query(r, 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 {
            bool oky = t.query(1, 1, n, l, r);
            cout << (oky ? "YES" : "NO") << nl;
        }
    }

    return 0;
}

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 17:29:33
Judged At
2024-10-03 13:21:56
Judged By
Score
50
Total Time
146ms
Peak Memory
22.316 MiB