답안 #894294

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
894294 2023-12-28T04:07:49 Z Olympia Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
77 / 100
3000 ms 238332 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) {
            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, tl, (tl + tr)/2,l, r), query(2 * dum + 1, (tl + tr)/2 + 1, tr, l, r);
        }
    }
    int query (int l, int r) {
        r += 1;
        vector<int> vec1, vec2;
        int ql = l, qr = r, sz = (int)vec.size()/2;
        for(ql += sz , qr += sz; ql < qr;ql >>= 1 , qr >>= 1){
            if(ql&1){
                vec1.push_back(ql++);
            }
            if(qr&1){
                vec2.push_back(--qr);
            }
        }
        reverse(vec2.begin(), vec2.end());
        for (int x: vec2) vec1.push_back(x);
        intervals = vec1;
        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, tl, (tl + tr)/2), build(2 * dum + 1, (tl + tr)/2 + 1, tr);
            vec[dum] = merge(vec[2 * dum], vec[2 * dum + 1]);
            std::merge(vec[2 * dum].v.begin(), vec[2 * dum].v.end(),
                       vec[2 * dum + 1].v.begin(), vec[2 * dum + 1].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( 1, 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:56:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for (int i = 1; i < intervals.size(); i++) {
      |                         ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 3 ms 856 KB Output is correct
12 Correct 5 ms 1880 KB Output is correct
13 Correct 5 ms 1880 KB Output is correct
14 Correct 7 ms 1884 KB Output is correct
15 Correct 7 ms 1884 KB Output is correct
16 Correct 6 ms 1884 KB Output is correct
17 Correct 6 ms 1884 KB Output is correct
18 Correct 6 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2325 ms 237988 KB Output is correct
2 Correct 2208 ms 237892 KB Output is correct
3 Correct 2241 ms 238212 KB Output is correct
4 Correct 2266 ms 238100 KB Output is correct
5 Correct 1570 ms 238144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 166 ms 28372 KB Output is correct
2 Correct 164 ms 28384 KB Output is correct
3 Correct 137 ms 28236 KB Output is correct
4 Correct 125 ms 28216 KB Output is correct
5 Correct 124 ms 28372 KB Output is correct
6 Correct 111 ms 28372 KB Output is correct
7 Correct 111 ms 28360 KB Output is correct
8 Correct 338 ms 28616 KB Output is correct
9 Correct 53 ms 604 KB Output is correct
10 Correct 333 ms 28372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 3 ms 856 KB Output is correct
12 Correct 5 ms 1880 KB Output is correct
13 Correct 5 ms 1880 KB Output is correct
14 Correct 7 ms 1884 KB Output is correct
15 Correct 7 ms 1884 KB Output is correct
16 Correct 6 ms 1884 KB Output is correct
17 Correct 6 ms 1884 KB Output is correct
18 Correct 6 ms 1884 KB Output is correct
19 Correct 388 ms 57184 KB Output is correct
20 Correct 387 ms 57324 KB Output is correct
21 Correct 321 ms 57292 KB Output is correct
22 Correct 341 ms 57412 KB Output is correct
23 Correct 325 ms 57180 KB Output is correct
24 Correct 273 ms 57396 KB Output is correct
25 Correct 268 ms 57260 KB Output is correct
26 Correct 291 ms 57408 KB Output is correct
27 Correct 304 ms 57408 KB Output is correct
28 Correct 299 ms 57412 KB Output is correct
29 Correct 293 ms 57408 KB Output is correct
30 Correct 290 ms 57408 KB Output is correct
31 Correct 297 ms 57412 KB Output is correct
32 Correct 310 ms 57408 KB Output is correct
33 Correct 305 ms 57392 KB Output is correct
34 Correct 258 ms 57256 KB Output is correct
35 Correct 252 ms 57400 KB Output is correct
36 Correct 249 ms 57408 KB Output is correct
37 Correct 252 ms 57196 KB Output is correct
38 Correct 239 ms 57408 KB Output is correct
39 Correct 990 ms 57312 KB Output is correct
40 Correct 1572 ms 57108 KB Output is correct
41 Correct 1217 ms 57412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 3 ms 856 KB Output is correct
12 Correct 5 ms 1880 KB Output is correct
13 Correct 5 ms 1880 KB Output is correct
14 Correct 7 ms 1884 KB Output is correct
15 Correct 7 ms 1884 KB Output is correct
16 Correct 6 ms 1884 KB Output is correct
17 Correct 6 ms 1884 KB Output is correct
18 Correct 6 ms 1884 KB Output is correct
19 Correct 2325 ms 237988 KB Output is correct
20 Correct 2208 ms 237892 KB Output is correct
21 Correct 2241 ms 238212 KB Output is correct
22 Correct 2266 ms 238100 KB Output is correct
23 Correct 1570 ms 238144 KB Output is correct
24 Correct 166 ms 28372 KB Output is correct
25 Correct 164 ms 28384 KB Output is correct
26 Correct 137 ms 28236 KB Output is correct
27 Correct 125 ms 28216 KB Output is correct
28 Correct 124 ms 28372 KB Output is correct
29 Correct 111 ms 28372 KB Output is correct
30 Correct 111 ms 28360 KB Output is correct
31 Correct 338 ms 28616 KB Output is correct
32 Correct 53 ms 604 KB Output is correct
33 Correct 333 ms 28372 KB Output is correct
34 Correct 388 ms 57184 KB Output is correct
35 Correct 387 ms 57324 KB Output is correct
36 Correct 321 ms 57292 KB Output is correct
37 Correct 341 ms 57412 KB Output is correct
38 Correct 325 ms 57180 KB Output is correct
39 Correct 273 ms 57396 KB Output is correct
40 Correct 268 ms 57260 KB Output is correct
41 Correct 291 ms 57408 KB Output is correct
42 Correct 304 ms 57408 KB Output is correct
43 Correct 299 ms 57412 KB Output is correct
44 Correct 293 ms 57408 KB Output is correct
45 Correct 290 ms 57408 KB Output is correct
46 Correct 297 ms 57412 KB Output is correct
47 Correct 310 ms 57408 KB Output is correct
48 Correct 305 ms 57392 KB Output is correct
49 Correct 258 ms 57256 KB Output is correct
50 Correct 252 ms 57400 KB Output is correct
51 Correct 249 ms 57408 KB Output is correct
52 Correct 252 ms 57196 KB Output is correct
53 Correct 239 ms 57408 KB Output is correct
54 Correct 990 ms 57312 KB Output is correct
55 Correct 1572 ms 57108 KB Output is correct
56 Correct 1217 ms 57412 KB Output is correct
57 Correct 2244 ms 238096 KB Output is correct
58 Correct 2406 ms 238172 KB Output is correct
59 Correct 2445 ms 238000 KB Output is correct
60 Correct 2418 ms 237932 KB Output is correct
61 Correct 2394 ms 238024 KB Output is correct
62 Correct 2429 ms 238108 KB Output is correct
63 Correct 1334 ms 238092 KB Output is correct
64 Correct 1373 ms 238020 KB Output is correct
65 Correct 1758 ms 238096 KB Output is correct
66 Correct 1723 ms 238092 KB Output is correct
67 Correct 1713 ms 237948 KB Output is correct
68 Correct 1735 ms 238332 KB Output is correct
69 Correct 1679 ms 238096 KB Output is correct
70 Correct 1697 ms 238052 KB Output is correct
71 Correct 1713 ms 238080 KB Output is correct
72 Correct 1654 ms 238016 KB Output is correct
73 Correct 1292 ms 238028 KB Output is correct
74 Correct 1371 ms 237976 KB Output is correct
75 Correct 1321 ms 238096 KB Output is correct
76 Correct 1328 ms 238024 KB Output is correct
77 Correct 1381 ms 237972 KB Output is correct
78 Execution timed out 3041 ms 237888 KB Time limit exceeded
79 Halted 0 ms 0 KB -