Submission #894280

# Submission time Handle Problem Language Result Execution time Memory
894280 2023-12-28T03:38:47 Z Olympia Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
1956 ms 244820 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;
    vector<int> v;
    Node (int mn, int mx) {
        this->mx = mx, this->mn = mn, this->val = 0;
    }
};
struct SegmentTree {
    vector<Node> vec;
    vector<int> nodes;
    Node merge (Node &left, Node &right) {
        if (left.mx == -1) {
            return right;
        }
        if (right.mx == -1) {
            return left;
        }
        Node ans = {min(left.mn, right.mn), max(left.mx, right.mx)};
        ans.val = max(left.val, right.val);
        if (right.mx < left.mx) {
            ans.val = max(ans.val, left.mx + right.mx);
        } else if (right.mn < left.mx) {
            ans.val = max(ans.val, *(--lower_bound(right.v.begin(), right.v.end(), left.mx)) + left.mx);
        }
        return ans;
    }
    vector<int> intervals;
    void query (int dum, int tl, int tr, int l, int r) {
        if (tl >= l && tr <= r) {
            intervals.push_back(dum);
        } else if (tl <= r && tr >= l) {
            query(2 * dum + 1, tl, (tl + tr)/2,l, r), query(2 * dum + 2, (tl + tr)/2 + 1, tr, l, r);
        }
    }
    int query (int l, int r) {
        Node ans = {-1, -1};
        while (l < r) {
            if (l & 1) {
                ans = merge(ans, vec[l++]);
            }
            if (r & 1) {
                ans = merge(ans, vec[r--]);
            }
            l /= 2;
            r /= 2;
        }
        return ans.val;
    }
    void build (int dum, int tl, int tr) {
        if (tl == tr) {
            vec[dum] = Node(nodes[tl], nodes[tl]);
            vec[dum].v = {nodes[tl]};
        } else {
            build(2 * dum + 1, tl, (tl + tr)/2), build(2 * dum + 2, (tl + tr)/2 + 1, tr);
            vec[dum] = merge(vec[2 * dum + 1], vec[2 * dum + 2]);
            std::merge(vec[2 * dum + 1].v.begin(), vec[2 * dum + 1].v.end(),
                       vec[2 * dum + 2].v.begin(), vec[2 * dum + 2].v.end(),
                       std::back_inserter(vec[dum].v));
        }
    }
    SegmentTree (vector<int> nodes) {
        this->nodes = nodes;
        int n = nodes.size();
        n = (1 << (int)log2(n)) * 2;
        vec.assign(2 * n, Node(INT_MAX, -INT_MAX));
        this->nodes.reserve(vec.size());
        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';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1956 ms 244820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 125 ms 28364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -