답안 #1063352

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1063352 2024-08-17T17:08:28 Z manhlinh1501 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
732 ms 67712 KB
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int MAXN = 1e6 + 5;

struct event {
    int l, r, x, p;
    event(int l = 0, int r = 0, int x = 0, int p = 0) : l(l), r(r), x(x), p(p) {}
};

int N, Q;
int a[MAXN];
event query[MAXN];
int ans[MAXN];

struct segment_tree {
    int N;
    int tree[MAXN * 4];

    void init(int _N) {
        N = _N;
    }

    void update(int p, int x) {
        int id = 1, l = 1, r = N;
        while(l < r) {
            int m = (l + r) / 2;
            if(p <= m) {
                id = id * 2;
                r = m;
            } else {
                id = id * 2 + 1;
                l = m + 1;
            }
        }
        tree[id] = x;
        while(id >= 1) {
            id >>= 1;
            tree[id] = max(tree[id * 2], tree[id * 2 + 1]);
        }
    }

    int get(int id, int l, int r, int u, int v) {
        if(r < u or l > v) return 0;
        if(u <= l and r <= v) return tree[id];
        int m = (l + r) / 2;
        return max(get(id * 2, l, m, u, v), get(id * 2 + 1, m + 1, r, u, v));
    }

    int get(int l, int r) {
        return get(1, 1, N, l, r);
    }
} ST;

signed main() {
#define TASK "code"

    if (fopen(TASK ".inp", "r")) {
        freopen(TASK ".inp", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> N >> Q;
    for(int i = 1; i <= N; i++) cin >> a[i];
    for(int i = 1; i <= Q; i++) {
        auto &[l, r, x, p] = query[i];
        cin >> l >> r >> x;
        p = i;
    }
    sort(query + 1, query + Q + 1, [&](const event a, const event b) {
        return a.r < b.r;
    });
    for(int i = 1; i <= Q; i++) {
        auto [l, r, x, p] = query[i];
//        cerr << l << " " << r << " " << x << " " << p << "\n";
    }
    int j = 1;
    ST.init(N);
    stack<int> S;
    for(int i = 1; i <= N; i++) {
        while(!S.empty() and a[S.top()] <= a[i])
            S.pop();
        if(!S.empty()) ST.update(S.top(), a[S.top()] + a[i]);
        S.push(i);

        while(j <= Q and query[j].r < i) j++;

        while(j <= Q and query[j].r == i) {
            ans[query[j].p] = (ST.get(query[j].l, query[j].r) <= query[j].x);
            j++;
        }
    }

    for(int i = 1; i <= Q; i++) cout << ans[i] << "\n";
    return (0 ^ 0);
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:78:14: warning: structured binding declaration set but not used [-Wunused-but-set-variable]
   78 |         auto [l, r, x, p] = query[i];
      |              ^~~~~~~~~~~~
sortbooks.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         freopen(TASK ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         freopen(TASK ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15960 KB Output is correct
2 Correct 6 ms 15964 KB Output is correct
3 Correct 6 ms 15964 KB Output is correct
4 Correct 6 ms 15960 KB Output is correct
5 Correct 6 ms 16092 KB Output is correct
6 Correct 6 ms 15964 KB Output is correct
7 Correct 6 ms 15960 KB Output is correct
8 Correct 6 ms 16136 KB Output is correct
9 Correct 6 ms 15964 KB Output is correct
10 Correct 6 ms 16128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15960 KB Output is correct
2 Correct 6 ms 15964 KB Output is correct
3 Correct 6 ms 15964 KB Output is correct
4 Correct 6 ms 15960 KB Output is correct
5 Correct 6 ms 16092 KB Output is correct
6 Correct 6 ms 15964 KB Output is correct
7 Correct 6 ms 15960 KB Output is correct
8 Correct 6 ms 16136 KB Output is correct
9 Correct 6 ms 15964 KB Output is correct
10 Correct 6 ms 16128 KB Output is correct
11 Correct 7 ms 16220 KB Output is correct
12 Correct 9 ms 16220 KB Output is correct
13 Correct 7 ms 16220 KB Output is correct
14 Correct 10 ms 16396 KB Output is correct
15 Correct 9 ms 16392 KB Output is correct
16 Correct 9 ms 16252 KB Output is correct
17 Correct 8 ms 16220 KB Output is correct
18 Correct 9 ms 16220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 702 ms 65852 KB Output is correct
2 Correct 713 ms 66964 KB Output is correct
3 Correct 718 ms 66640 KB Output is correct
4 Correct 732 ms 66916 KB Output is correct
5 Correct 576 ms 59004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 20048 KB Output is correct
2 Correct 59 ms 19932 KB Output is correct
3 Correct 53 ms 19024 KB Output is correct
4 Correct 52 ms 19028 KB Output is correct
5 Correct 54 ms 18892 KB Output is correct
6 Correct 47 ms 18768 KB Output is correct
7 Correct 48 ms 18768 KB Output is correct
8 Correct 52 ms 18768 KB Output is correct
9 Correct 30 ms 18000 KB Output is correct
10 Correct 57 ms 18688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15960 KB Output is correct
2 Correct 6 ms 15964 KB Output is correct
3 Correct 6 ms 15964 KB Output is correct
4 Correct 6 ms 15960 KB Output is correct
5 Correct 6 ms 16092 KB Output is correct
6 Correct 6 ms 15964 KB Output is correct
7 Correct 6 ms 15960 KB Output is correct
8 Correct 6 ms 16136 KB Output is correct
9 Correct 6 ms 15964 KB Output is correct
10 Correct 6 ms 16128 KB Output is correct
11 Correct 7 ms 16220 KB Output is correct
12 Correct 9 ms 16220 KB Output is correct
13 Correct 7 ms 16220 KB Output is correct
14 Correct 10 ms 16396 KB Output is correct
15 Correct 9 ms 16392 KB Output is correct
16 Correct 9 ms 16252 KB Output is correct
17 Correct 8 ms 16220 KB Output is correct
18 Correct 9 ms 16220 KB Output is correct
19 Correct 138 ms 26472 KB Output is correct
20 Correct 137 ms 26836 KB Output is correct
21 Correct 129 ms 26448 KB Output is correct
22 Correct 139 ms 26480 KB Output is correct
23 Correct 125 ms 26448 KB Output is correct
24 Correct 110 ms 24400 KB Output is correct
25 Correct 104 ms 24172 KB Output is correct
26 Correct 113 ms 24656 KB Output is correct
27 Correct 109 ms 24560 KB Output is correct
28 Correct 112 ms 24436 KB Output is correct
29 Correct 118 ms 24660 KB Output is correct
30 Correct 114 ms 24576 KB Output is correct
31 Correct 114 ms 24556 KB Output is correct
32 Correct 119 ms 24428 KB Output is correct
33 Correct 117 ms 24656 KB Output is correct
34 Correct 100 ms 24144 KB Output is correct
35 Correct 99 ms 24144 KB Output is correct
36 Correct 96 ms 24052 KB Output is correct
37 Correct 97 ms 23888 KB Output is correct
38 Correct 97 ms 24132 KB Output is correct
39 Correct 103 ms 23712 KB Output is correct
40 Correct 80 ms 22096 KB Output is correct
41 Correct 97 ms 22896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15960 KB Output is correct
2 Correct 6 ms 15964 KB Output is correct
3 Correct 6 ms 15964 KB Output is correct
4 Correct 6 ms 15960 KB Output is correct
5 Correct 6 ms 16092 KB Output is correct
6 Correct 6 ms 15964 KB Output is correct
7 Correct 6 ms 15960 KB Output is correct
8 Correct 6 ms 16136 KB Output is correct
9 Correct 6 ms 15964 KB Output is correct
10 Correct 6 ms 16128 KB Output is correct
11 Correct 7 ms 16220 KB Output is correct
12 Correct 9 ms 16220 KB Output is correct
13 Correct 7 ms 16220 KB Output is correct
14 Correct 10 ms 16396 KB Output is correct
15 Correct 9 ms 16392 KB Output is correct
16 Correct 9 ms 16252 KB Output is correct
17 Correct 8 ms 16220 KB Output is correct
18 Correct 9 ms 16220 KB Output is correct
19 Correct 702 ms 65852 KB Output is correct
20 Correct 713 ms 66964 KB Output is correct
21 Correct 718 ms 66640 KB Output is correct
22 Correct 732 ms 66916 KB Output is correct
23 Correct 576 ms 59004 KB Output is correct
24 Correct 65 ms 20048 KB Output is correct
25 Correct 59 ms 19932 KB Output is correct
26 Correct 53 ms 19024 KB Output is correct
27 Correct 52 ms 19028 KB Output is correct
28 Correct 54 ms 18892 KB Output is correct
29 Correct 47 ms 18768 KB Output is correct
30 Correct 48 ms 18768 KB Output is correct
31 Correct 52 ms 18768 KB Output is correct
32 Correct 30 ms 18000 KB Output is correct
33 Correct 57 ms 18688 KB Output is correct
34 Correct 138 ms 26472 KB Output is correct
35 Correct 137 ms 26836 KB Output is correct
36 Correct 129 ms 26448 KB Output is correct
37 Correct 139 ms 26480 KB Output is correct
38 Correct 125 ms 26448 KB Output is correct
39 Correct 110 ms 24400 KB Output is correct
40 Correct 104 ms 24172 KB Output is correct
41 Correct 113 ms 24656 KB Output is correct
42 Correct 109 ms 24560 KB Output is correct
43 Correct 112 ms 24436 KB Output is correct
44 Correct 118 ms 24660 KB Output is correct
45 Correct 114 ms 24576 KB Output is correct
46 Correct 114 ms 24556 KB Output is correct
47 Correct 119 ms 24428 KB Output is correct
48 Correct 117 ms 24656 KB Output is correct
49 Correct 100 ms 24144 KB Output is correct
50 Correct 99 ms 24144 KB Output is correct
51 Correct 96 ms 24052 KB Output is correct
52 Correct 97 ms 23888 KB Output is correct
53 Correct 97 ms 24132 KB Output is correct
54 Correct 103 ms 23712 KB Output is correct
55 Correct 80 ms 22096 KB Output is correct
56 Correct 97 ms 22896 KB Output is correct
57 Correct 695 ms 67712 KB Output is correct
58 Correct 698 ms 67668 KB Output is correct
59 Correct 675 ms 67408 KB Output is correct
60 Correct 687 ms 67408 KB Output is correct
61 Correct 684 ms 67432 KB Output is correct
62 Correct 709 ms 67576 KB Output is correct
63 Correct 509 ms 57428 KB Output is correct
64 Correct 517 ms 57540 KB Output is correct
65 Correct 584 ms 59244 KB Output is correct
66 Correct 589 ms 59220 KB Output is correct
67 Correct 584 ms 59220 KB Output is correct
68 Correct 604 ms 59472 KB Output is correct
69 Correct 614 ms 59500 KB Output is correct
70 Correct 592 ms 59332 KB Output is correct
71 Correct 623 ms 59400 KB Output is correct
72 Correct 600 ms 59504 KB Output is correct
73 Correct 519 ms 55892 KB Output is correct
74 Correct 521 ms 56916 KB Output is correct
75 Correct 488 ms 56108 KB Output is correct
76 Correct 485 ms 55892 KB Output is correct
77 Correct 508 ms 55980 KB Output is correct
78 Correct 554 ms 56148 KB Output is correct
79 Correct 427 ms 46640 KB Output is correct
80 Correct 542 ms 50452 KB Output is correct