답안 #894142

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
894142 2023-12-28T01:54:45 Z Olympia Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
3000 ms 172500 KB
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <cassert>
#include <algorithm>
using namespace std;
struct Node {
    int mx;
    int mn;
    int val;
    int l;
    int r;
    set<int> s;
    Node (int l, int r) {
        this->mx = INT_MIN, this->mn = INT_MAX, this->val = 0, this->l = l, this->r = r;
    }
};
struct SegmentTree {
    vector<Node> vec;
    vector<int> nodes;
    Node merge (Node left, Node right, bool b) {
        if (left.l == -1) {
            return right;
        }
        if (right.l == -1) {
            return left;
        }
        Node ans = Node(left.l, right.r);
        if (b) {
            for (int x: left.s) {
                ans.s.insert(x);
            }
            for (int x: right.s) {
                ans.s.insert(x);
            }
        }
        ans.mn = min(left.mn, right.mn);
        ans.mx = max(left.mx, right.mx);
        ans.val = max(left.val, right.val);
        if (right.mn < left.mx) {
            ans.val = max(ans.val, *(--right.s.lower_bound(left.mx)) + left.mx);
        }
        return ans;
    }
    Node query (int dum, int tl, int tr, int l, int r) {
        if (tl >= l && tr <= r) {
            return vec[dum];
        }
        if (tl > r || tr < l) {
            return {-1, -1};
        }
        return merge(query(2 * dum + 1, tl, (tl + tr)/2,l, r), query(2 * dum + 2, (tl + tr)/2 + 1, tr, l, r), false);
    }
    int query (int l, int r) {
        return query(0, 0, (int)vec.size()/2 - 1, l, r).val;
    }
    Node build (int dum, int tl, int tr) {
        if (tl == tr) {
            vec[dum] = Node(tl, tr);
            vec[dum].mn = vec[dum].mx = nodes[tl];
            vec[dum].s = {nodes[tl]};
            return vec[dum];
        }
        build(2 * dum + 1, tl, (tl + tr)/2);
        build(2 * dum + 2, (tl + tr)/2 + 1, tr);
        return vec[dum] = merge( build(2 * dum + 1, tl, (tl + tr)/2), build(2 * dum + 2, (tl + tr)/2 + 1, tr), true);
    }
    SegmentTree (vector<int> nodes) {
        this->nodes = nodes;
        int n = nodes.size();
        n = (1 << (int)log2(n)) * 2;
        vec.assign(2 * n, Node(0, 0));
        while (this->nodes.size() < vec.size()) {
            this->nodes.push_back((int)1e9);
        }
        build(0, 0, (int)vec.size()/2 - 1);
    }
};
int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, q;
    cin >> n >> q;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    SegmentTree st(v);
    while (q--) {
        int l, r, k;
        cin >> l >> r >> k;
        l--, r--;
        cout << (st.query(l, r) <= k) << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 7 ms 604 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 7 ms 604 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3015 ms 172500 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3061 ms 25108 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 7 ms 604 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 7 ms 604 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -