/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 81ms 2.77 MiB
#4 Accepted 185ms 8.133 MiB
#5 Accepted 125ms 6.82 MiB
#6 Accepted 75ms 2.27 MiB
#7 Accepted 1ms 532.0 KiB
#8 Accepted 1ms 324.0 KiB
#9 Accepted 159ms 8.496 MiB
#10 Accepted 228ms 9.895 MiB

Code

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1000000007;
#define sz(x) (ll)(x).size()
#define rd ({ll x; cin >> x; x; })
#define dbg(x) cerr << "[" #x "]  " << (x) << "\n\n"
// #define errv(x) {cerr << "["#x"]  ["; for (const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
// #define errvn(x, n) {cerr << "["#x"]  ["; for (auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
// #define cerr if(0)cerr
#define xx first
#define yy second
mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
/*_________________________________________________________________________________________________________________________*/

void Solve()
{
    ll n;
    cin >> n;
    vector<ll> arr(n + 2, 0);
    arr[n + 1] = LLONG_MAX;
    for (int i = 1; i <= n; i++)
        cin >> arr[i];
    set<ll> problems;
    for (int i = 1; i <= n; i++) {
        if (!(arr[i - 1] <= arr[i] && arr[i] <= arr[i + 1]))
            problems.insert(i);
    }
    ll q;
    cin >> q;
    while (q--) {
        ll qr, x, y;
        cin >> qr >> x >> y;

        if (qr == 2) {
            if (y - x + 1 < 10) {
                vector<ll> tmp, tmp2;
                for (int i = x; i <= y; i++)
                    tmp.push_back(arr[i]);
                tmp2 = tmp;
                sort(tmp2.begin(), tmp2.end());
                if (tmp == tmp2)
                    cout << "YES\n";
                else
                    cout << "NO\n";
                continue;
            }
            if (arr[x + 1] < arr[x]) {
                cout << "NO\n";
                continue;
            }
            if (arr[y - 1] > arr[y]) {
                cout << "NO\n";
                continue;
            }
            auto it = problems.upper_bound(x);
            if (it == problems.end() || *it >= y)
                cout << "YES\n";
            else
                cout << "NO\n";
        } else {
            problems.erase(x - 1);
            problems.erase(x);
            problems.erase(x + 1);
            arr[x] = y;
            if (x - 1 > 0) {
                if (!(arr[x - 2] <= arr[x - 1] && arr[x - 1] <= arr[x]))
                    problems.insert(x - 1);
            }
            if (x + 1 <= n) {
                if (!(arr[x] <= arr[x + 1] && arr[x + 1] <= arr[x + 2]))
                    problems.insert(x + 1);
            }
            if (!(arr[x - 1] <= arr[x] && arr[x] <= arr[x + 1]))
                problems.insert(x);
        }
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; i++) {
        // cout << "Case #" << i << ": "; // cout << "Case " << i << ": ";
        Solve();
    }
    return 0;
}
// Coded by Tahsin Arafat (@TahsinArafat)

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:46:17
Judged At
2024-08-16 16:46:17
Judged By
Score
100
Total Time
228ms
Peak Memory
9.895 MiB