/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 532.0 KiB
#2 Wrong Answer 1ms 532.0 KiB

Code

#include <iostream>
#include <vector>

using namespace std;
void updateIsSorted(vector<bool>& isSorted, const vector<int>& arr, int start, int end) {
    for (int i = start; i <= end; ++i) {
        if (i > 0) {
            isSorted[i] = arr[i - 1] <= arr[i];
        }
    }
}
int main() {
    int N, Q;
    cin >> N >> Q;
    
    vector<int> arr(N);
    vector<bool> isSorted(N - 1, true);
    
    for (int i = 0; i < N; ++i) {
        cin >> arr[i];
    }
    for (int i = 0; i < N - 1; ++i) {
        isSorted[i] = arr[i] <= arr[i + 1];
    }
    
    for (int i = 0; i < Q; ++i) {
        int type;
        cin >> type;
        if (type == 1) {
            int idx, x;
            cin >> idx >> x;
            --idx; 
            arr[idx] = x;
            
            if (idx > 0) {
                isSorted[idx - 1] = arr[idx - 1] <= arr[idx];
            }
            if (idx < N - 1) {
                isSorted[idx] = arr[idx] <= arr[idx + 1];
            }
        } else if (type == 2) {
            int l, r;
            cin >> l >> r;
            --l; --r; 
            bool sorted = true;
            for (int j = l; j < r; ++j) {
                if (!isSorted[j]) {
                    sorted = false;
                    break;
                }
            }
            cout << (sorted ? "YES" : "NO") << endl;
        }
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1085 Sorted or !Sorted
Contest
Bangladesh 2.0
Language
C++17 (G++ 13.2.0)
Submit At
2024-08-16 16:06:49
Judged At
2024-11-11 03:16:05
Judged By
Score
0
Total Time
1ms
Peak Memory
532.0 KiB