/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 324.0 KiB
#2 Wrong Answer 1ms 320.0 KiB
#3 Wrong Answer 67ms 1.32 MiB
#4 Wrong Answer 31ms 1.312 MiB
#5 Wrong Answer 30ms 1.312 MiB
#6 Wrong Answer 31ms 1.32 MiB
#7 Wrong Answer 1ms 532.0 KiB
#8 Wrong Answer 1ms 324.0 KiB
#9 Wrong Answer 31ms 1.312 MiB
#10 Runtime Error 399ms 1.605 MiB

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-10-03 13:28:38
Judged By
Score
0
Total Time
399ms
Peak Memory
1.605 MiB