답안 #894254

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
894254 2023-12-28T03:07:25 Z Olympia Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
77 / 100
3000 ms 262144 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) {
        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, (int)vec.size()/2 - 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;
        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';
    }
}

Compilation message

sortbooks.cpp: In member function 'int SegmentTree::query(int, int)':
sortbooks.cpp:54:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for (int i = 1; i < intervals.size(); i++) {
      |                         ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 456 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 456 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 3 ms 924 KB Output is correct
12 Correct 4 ms 2140 KB Output is correct
13 Correct 5 ms 2140 KB Output is correct
14 Correct 6 ms 2204 KB Output is correct
15 Correct 8 ms 2136 KB Output is correct
16 Correct 7 ms 2140 KB Output is correct
17 Correct 6 ms 2028 KB Output is correct
18 Correct 5 ms 2140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2154 ms 259532 KB Output is correct
2 Correct 2072 ms 259116 KB Output is correct
3 Correct 2115 ms 258644 KB Output is correct
4 Correct 2192 ms 259884 KB Output is correct
5 Correct 1477 ms 259824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 29816 KB Output is correct
2 Correct 165 ms 29860 KB Output is correct
3 Correct 109 ms 29836 KB Output is correct
4 Correct 111 ms 29848 KB Output is correct
5 Correct 116 ms 29776 KB Output is correct
6 Correct 93 ms 29668 KB Output is correct
7 Correct 84 ms 29596 KB Output is correct
8 Correct 335 ms 29564 KB Output is correct
9 Correct 37 ms 1900 KB Output is correct
10 Correct 315 ms 29564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 456 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 3 ms 924 KB Output is correct
12 Correct 4 ms 2140 KB Output is correct
13 Correct 5 ms 2140 KB Output is correct
14 Correct 6 ms 2204 KB Output is correct
15 Correct 8 ms 2136 KB Output is correct
16 Correct 7 ms 2140 KB Output is correct
17 Correct 6 ms 2028 KB Output is correct
18 Correct 5 ms 2140 KB Output is correct
19 Correct 335 ms 61984 KB Output is correct
20 Correct 368 ms 62016 KB Output is correct
21 Correct 301 ms 61956 KB Output is correct
22 Correct 280 ms 61872 KB Output is correct
23 Correct 276 ms 61748 KB Output is correct
24 Correct 199 ms 61912 KB Output is correct
25 Correct 221 ms 62000 KB Output is correct
26 Correct 245 ms 61856 KB Output is correct
27 Correct 242 ms 61844 KB Output is correct
28 Correct 262 ms 61752 KB Output is correct
29 Correct 253 ms 62000 KB Output is correct
30 Correct 241 ms 61616 KB Output is correct
31 Correct 273 ms 61628 KB Output is correct
32 Correct 278 ms 61920 KB Output is correct
33 Correct 286 ms 61564 KB Output is correct
34 Correct 196 ms 61744 KB Output is correct
35 Correct 186 ms 61788 KB Output is correct
36 Correct 194 ms 61820 KB Output is correct
37 Correct 189 ms 62000 KB Output is correct
38 Correct 200 ms 61932 KB Output is correct
39 Correct 980 ms 61252 KB Output is correct
40 Correct 1584 ms 60048 KB Output is correct
41 Correct 1193 ms 60692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 456 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 3 ms 924 KB Output is correct
12 Correct 4 ms 2140 KB Output is correct
13 Correct 5 ms 2140 KB Output is correct
14 Correct 6 ms 2204 KB Output is correct
15 Correct 8 ms 2136 KB Output is correct
16 Correct 7 ms 2140 KB Output is correct
17 Correct 6 ms 2028 KB Output is correct
18 Correct 5 ms 2140 KB Output is correct
19 Correct 2154 ms 259532 KB Output is correct
20 Correct 2072 ms 259116 KB Output is correct
21 Correct 2115 ms 258644 KB Output is correct
22 Correct 2192 ms 259884 KB Output is correct
23 Correct 1477 ms 259824 KB Output is correct
24 Correct 150 ms 29816 KB Output is correct
25 Correct 165 ms 29860 KB Output is correct
26 Correct 109 ms 29836 KB Output is correct
27 Correct 111 ms 29848 KB Output is correct
28 Correct 116 ms 29776 KB Output is correct
29 Correct 93 ms 29668 KB Output is correct
30 Correct 84 ms 29596 KB Output is correct
31 Correct 335 ms 29564 KB Output is correct
32 Correct 37 ms 1900 KB Output is correct
33 Correct 315 ms 29564 KB Output is correct
34 Correct 335 ms 61984 KB Output is correct
35 Correct 368 ms 62016 KB Output is correct
36 Correct 301 ms 61956 KB Output is correct
37 Correct 280 ms 61872 KB Output is correct
38 Correct 276 ms 61748 KB Output is correct
39 Correct 199 ms 61912 KB Output is correct
40 Correct 221 ms 62000 KB Output is correct
41 Correct 245 ms 61856 KB Output is correct
42 Correct 242 ms 61844 KB Output is correct
43 Correct 262 ms 61752 KB Output is correct
44 Correct 253 ms 62000 KB Output is correct
45 Correct 241 ms 61616 KB Output is correct
46 Correct 273 ms 61628 KB Output is correct
47 Correct 278 ms 61920 KB Output is correct
48 Correct 286 ms 61564 KB Output is correct
49 Correct 196 ms 61744 KB Output is correct
50 Correct 186 ms 61788 KB Output is correct
51 Correct 194 ms 61820 KB Output is correct
52 Correct 189 ms 62000 KB Output is correct
53 Correct 200 ms 61932 KB Output is correct
54 Correct 980 ms 61252 KB Output is correct
55 Correct 1584 ms 60048 KB Output is correct
56 Correct 1193 ms 60692 KB Output is correct
57 Correct 2171 ms 259420 KB Output is correct
58 Correct 2175 ms 260256 KB Output is correct
59 Correct 2182 ms 260268 KB Output is correct
60 Correct 2128 ms 260388 KB Output is correct
61 Correct 2316 ms 260276 KB Output is correct
62 Correct 2365 ms 260024 KB Output is correct
63 Correct 1044 ms 258980 KB Output is correct
64 Correct 1068 ms 258764 KB Output is correct
65 Correct 1509 ms 260216 KB Output is correct
66 Correct 1583 ms 262144 KB Output is correct
67 Correct 1572 ms 262144 KB Output is correct
68 Correct 1594 ms 262144 KB Output is correct
69 Correct 1529 ms 262144 KB Output is correct
70 Correct 1606 ms 262144 KB Output is correct
71 Correct 1581 ms 262144 KB Output is correct
72 Correct 1490 ms 262144 KB Output is correct
73 Correct 1063 ms 261852 KB Output is correct
74 Correct 1060 ms 262144 KB Output is correct
75 Correct 1055 ms 261872 KB Output is correct
76 Correct 1075 ms 261976 KB Output is correct
77 Correct 1058 ms 261980 KB Output is correct
78 Execution timed out 3060 ms 242596 KB Time limit exceeded
79 Halted 0 ms 0 KB -