/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 1ms 540.0 KiB
#3 Accepted 1ms 612.0 KiB
#4 Accepted 1ms 540.0 KiB
#5 Accepted 1ms 540.0 KiB
#6 Accepted 1ms 540.0 KiB
#7 Accepted 1ms 540.0 KiB
#8 Accepted 1ms 540.0 KiB
#9 Accepted 1ms 540.0 KiB
#10 Accepted 1ms 540.0 KiB
#11 Accepted 1ms 540.0 KiB
#12 Accepted 1ms 644.0 KiB
#13 Accepted 2ms 504.0 KiB
#14 Accepted 2ms 540.0 KiB
#15 Accepted 2ms 336.0 KiB
#16 Accepted 2ms 540.0 KiB
#17 Accepted 2ms 540.0 KiB
#18 Accepted 2ms 540.0 KiB
#19 Accepted 2ms 328.0 KiB
#20 Accepted 2ms 332.0 KiB
#21 Accepted 1ms 584.0 KiB
#22 Accepted 1ms 516.0 KiB
#23 Accepted 1ms 516.0 KiB
#24 Accepted 1ms 540.0 KiB
#25 Accepted 1ms 540.0 KiB
#26 Accepted 1ms 448.0 KiB
#27 Accepted 1ms 448.0 KiB
#28 Accepted 1ms 484.0 KiB
#29 Accepted 1ms 540.0 KiB
#30 Accepted 1ms 540.0 KiB
#31 Accepted 1ms 540.0 KiB
#32 Accepted 1ms 432.0 KiB
#33 Accepted 1ms 540.0 KiB
#34 Accepted 1ms 332.0 KiB
#35 Accepted 1ms 516.0 KiB
#36 Accepted 1ms 412.0 KiB
#37 Accepted 1ms 540.0 KiB
#38 Accepted 1ms 492.0 KiB
#39 Accepted 1ms 540.0 KiB
#40 Accepted 1ms 540.0 KiB
#41 Accepted 1ms 540.0 KiB
#42 Accepted 1ms 348.0 KiB
#43 Accepted 1ms 332.0 KiB
#44 Accepted 1ms 540.0 KiB
#45 Accepted 1ms 456.0 KiB
#46 Accepted 1ms 540.0 KiB
#47 Accepted 1ms 772.0 KiB
#48 Accepted 1ms 540.0 KiB
#49 Accepted 1ms 584.0 KiB
#50 Accepted 1ms 540.0 KiB
#51 Accepted 1ms 540.0 KiB
#52 Accepted 1ms 540.0 KiB
#53 Accepted 1ms 644.0 KiB
#54 Accepted 1ms 328.0 KiB
#55 Accepted 1ms 540.0 KiB
#56 Accepted 1ms 580.0 KiB
#57 Accepted 1ms 540.0 KiB
#58 Accepted 1ms 540.0 KiB
#59 Accepted 1ms 556.0 KiB
#60 Accepted 1ms 540.0 KiB
#61 Accepted 1ms 496.0 KiB
#62 Accepted 1ms 540.0 KiB
#63 Accepted 1ms 540.0 KiB
#64 Accepted 1ms 540.0 KiB
#65 Accepted 1ms 772.0 KiB
#66 Accepted 1ms 540.0 KiB
#67 Accepted 1ms 540.0 KiB
#68 Accepted 1ms 372.0 KiB
#69 Accepted 1ms 540.0 KiB
#70 Accepted 1ms 584.0 KiB
#71 Accepted 1ms 540.0 KiB
#72 Accepted 1ms 540.0 KiB
#73 Accepted 1ms 696.0 KiB
#74 Accepted 1ms 540.0 KiB
#75 Accepted 1ms 540.0 KiB
#76 Accepted 1ms 412.0 KiB
#77 Accepted 1ms 392.0 KiB
#78 Accepted 1ms 540.0 KiB
#79 Accepted 1ms 540.0 KiB
#80 Accepted 1ms 540.0 KiB
#81 Accepted 1ms 540.0 KiB
#82 Wrong Answer 1ms 348.0 KiB
#83 Wrong Answer 1ms 468.0 KiB

Code

#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll = long long;

const int N = 2e5 + 9;

struct Segment_Tree {
    pair<int, int> t[4 * N];

    pair<int, int> merge(auto &l, auto &r) { // <== Change this function
        return {min(l.second, r.second), max(l.first, r.first)};
    }
    void build(int node, int st, int en, vector<int> &arr) { //=> O(N)
        if (st == en) {
            t[node] = {arr[st], arr[st]};
            return;
        }
        int mid = (st + en) >> 1;
        build(node << 1, st, mid, arr); // divide left side
        build(node << 1 | 1, mid + 1, en, arr); // divide right side
        // Merging left and right portion
        auto &Cur = t[node];
        auto &Left = t[node << 1];
        auto &Right = t[node << 1 | 1];
        Cur = merge(Left, Right);
        return;
    }
    void update(int node, int st, int en, int idx, int val) { //=> O(log n)
        if (st == en) {
            t[node] = {val, val};
            return;
        }
        int mid = (st + en) >> 1;
        if (idx <= mid) update(node << 1, st, mid, idx, val);
        else update(node << 1 | 1, mid + 1, en, idx, val);
        // Merging left and right portion
        auto &Cur = t[node];
        auto &Left = t[node << 1];
        auto &Right = t[node << 1 | 1];
        Cur = merge(Left, Right);
        return;
    }
} st1;

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n, qry;
    cin >> n >> qry;
    vector<int> arr(n + 1);
    for(int i = 1; i <= n; i++) cin >> arr[i];
    st1.build(1, 1, n, arr);
    int i, v, q;
    while(qry--) {
        cin >> i >> v >> q;
        assert(q <= 1000000000 && arr[i] <= 1000000000);
        st1.update(1, 1, n, i, v);
        if(q) cout << st1.t[1].second << endl;
        else cout << st1.t[1].first << endl;
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1169 Thakur vs Roy again
Language
C++17 (G++ 13.2.0)
Submit At
2025-03-20 20:28:53
Judged At
2025-03-20 20:28:53
Judged By
Score
81
Total Time
2ms
Peak Memory
772.0 KiB