Submission #894267

# Submission time Handle Problem Language Result Execution time Memory
894267 2023-12-28T03:12:29 Z Olympia Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
1563 ms 112400 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 () {
        this->mx = INT_MIN, this->mn = INT_MAX, this-> val = 0;
    }
    Node (int mn, int mx) {
        this->mx = mx, this->mn = mn, this->val = 0;
    }
} vec[(int)1e6];
struct SegmentTree {
    vector<int> nodes;
    int n;
    Node merge (Node &left, Node &right) {
        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) {
            int l = 0;
            int r = right.v.size() - 1;
            while (l != r) {
                int m = (l + r + 1)/2;
                if (right.v[m] < left.mx) {
                    l = m;
                } else {
                    r = m - 1;
                }
            }
            ans.val = max(ans.val, right.v[l] + 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) {
        intervals.clear();
        query(0, 0, n - 1, l, r);
        Node ans = vec[intervals[0]];
        for (int i = 1; i < intervals.size(); i++) {
            ans = merge(ans, vec[intervals[i]]);
        }
        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]);
        vec[dum].v.reserve(vec[2 * dum + 1].v.size() + vec[2 * dum + 2].v.size());
        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;
        this->n = nodes.size();
        this->n = (1 << (int)log2(n)) * 2;
        this->nodes.reserve(2 * n);
        while (this->nodes.size() < 2 * n) {
            this->nodes.push_back((int)1e9);
        }
        build(0, 0, n - 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';
    }
}

Compilation message

sortbooks.cpp: In member function 'int SegmentTree::query(int, int)':
sortbooks.cpp:57:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         for (int i = 1; i < intervals.size(); i++) {
      |                         ~~^~~~~~~~~~~~~~~~~~
sortbooks.cpp: In constructor 'SegmentTree::SegmentTree(std::vector<int>)':
sortbooks.cpp:80:35: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   80 |         while (this->nodes.size() < 2 * n) {
      |                ~~~~~~~~~~~~~~~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 39512 KB Output is correct
2 Correct 9 ms 39512 KB Output is correct
3 Correct 9 ms 39516 KB Output is correct
4 Correct 9 ms 39516 KB Output is correct
5 Correct 9 ms 39768 KB Output is correct
6 Correct 9 ms 39516 KB Output is correct
7 Correct 9 ms 39512 KB Output is correct
8 Correct 10 ms 39516 KB Output is correct
9 Correct 10 ms 39552 KB Output is correct
10 Correct 10 ms 39516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 39512 KB Output is correct
2 Correct 9 ms 39512 KB Output is correct
3 Correct 9 ms 39516 KB Output is correct
4 Correct 9 ms 39516 KB Output is correct
5 Correct 9 ms 39768 KB Output is correct
6 Correct 9 ms 39516 KB Output is correct
7 Correct 9 ms 39512 KB Output is correct
8 Correct 10 ms 39516 KB Output is correct
9 Correct 10 ms 39552 KB Output is correct
10 Correct 10 ms 39516 KB Output is correct
11 Correct 11 ms 39772 KB Output is correct
12 Correct 12 ms 40540 KB Output is correct
13 Correct 13 ms 40536 KB Output is correct
14 Correct 15 ms 40596 KB Output is correct
15 Correct 15 ms 40536 KB Output is correct
16 Correct 14 ms 40540 KB Output is correct
17 Correct 13 ms 40540 KB Output is correct
18 Correct 13 ms 40540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 125 ms 112400 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 170 ms 57792 KB Output is correct
2 Correct 144 ms 58524 KB Output is correct
3 Correct 114 ms 58424 KB Output is correct
4 Correct 112 ms 58296 KB Output is correct
5 Correct 107 ms 58496 KB Output is correct
6 Correct 95 ms 58436 KB Output is correct
7 Correct 96 ms 58648 KB Output is correct
8 Correct 333 ms 58580 KB Output is correct
9 Correct 45 ms 40972 KB Output is correct
10 Correct 332 ms 58176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 39512 KB Output is correct
2 Correct 9 ms 39512 KB Output is correct
3 Correct 9 ms 39516 KB Output is correct
4 Correct 9 ms 39516 KB Output is correct
5 Correct 9 ms 39768 KB Output is correct
6 Correct 9 ms 39516 KB Output is correct
7 Correct 9 ms 39512 KB Output is correct
8 Correct 10 ms 39516 KB Output is correct
9 Correct 10 ms 39552 KB Output is correct
10 Correct 10 ms 39516 KB Output is correct
11 Correct 11 ms 39772 KB Output is correct
12 Correct 12 ms 40540 KB Output is correct
13 Correct 13 ms 40536 KB Output is correct
14 Correct 15 ms 40596 KB Output is correct
15 Correct 15 ms 40536 KB Output is correct
16 Correct 14 ms 40540 KB Output is correct
17 Correct 13 ms 40540 KB Output is correct
18 Correct 13 ms 40540 KB Output is correct
19 Correct 359 ms 80256 KB Output is correct
20 Correct 361 ms 80628 KB Output is correct
21 Correct 300 ms 80772 KB Output is correct
22 Correct 299 ms 80716 KB Output is correct
23 Correct 300 ms 80688 KB Output is correct
24 Correct 210 ms 80476 KB Output is correct
25 Correct 226 ms 80384 KB Output is correct
26 Correct 237 ms 80724 KB Output is correct
27 Correct 255 ms 80728 KB Output is correct
28 Correct 249 ms 80644 KB Output is correct
29 Correct 274 ms 80852 KB Output is correct
30 Correct 250 ms 80524 KB Output is correct
31 Correct 251 ms 80176 KB Output is correct
32 Correct 271 ms 80748 KB Output is correct
33 Correct 259 ms 80196 KB Output is correct
34 Correct 213 ms 80460 KB Output is correct
35 Correct 205 ms 80524 KB Output is correct
36 Correct 204 ms 80180 KB Output is correct
37 Correct 219 ms 80248 KB Output is correct
38 Correct 203 ms 80436 KB Output is correct
39 Correct 961 ms 79292 KB Output is correct
40 Correct 1563 ms 78596 KB Output is correct
41 Correct 1164 ms 79332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 39512 KB Output is correct
2 Correct 9 ms 39512 KB Output is correct
3 Correct 9 ms 39516 KB Output is correct
4 Correct 9 ms 39516 KB Output is correct
5 Correct 9 ms 39768 KB Output is correct
6 Correct 9 ms 39516 KB Output is correct
7 Correct 9 ms 39512 KB Output is correct
8 Correct 10 ms 39516 KB Output is correct
9 Correct 10 ms 39552 KB Output is correct
10 Correct 10 ms 39516 KB Output is correct
11 Correct 11 ms 39772 KB Output is correct
12 Correct 12 ms 40540 KB Output is correct
13 Correct 13 ms 40536 KB Output is correct
14 Correct 15 ms 40596 KB Output is correct
15 Correct 15 ms 40536 KB Output is correct
16 Correct 14 ms 40540 KB Output is correct
17 Correct 13 ms 40540 KB Output is correct
18 Correct 13 ms 40540 KB Output is correct
19 Runtime error 125 ms 112400 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -