답안 #1063353

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1063353 2024-08-17T17:09:27 Z manhlinh1501 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
755 ms 59476 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[(1 << 21) + 5];

    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 5 ms 15960 KB Output is correct
2 Correct 6 ms 15964 KB Output is correct
3 Correct 6 ms 15904 KB Output is correct
4 Correct 6 ms 15964 KB Output is correct
5 Correct 6 ms 15964 KB Output is correct
6 Correct 6 ms 15964 KB Output is correct
7 Correct 6 ms 15964 KB Output is correct
8 Correct 6 ms 15964 KB Output is correct
9 Correct 6 ms 15964 KB Output is correct
10 Correct 6 ms 15964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 15960 KB Output is correct
2 Correct 6 ms 15964 KB Output is correct
3 Correct 6 ms 15904 KB Output is correct
4 Correct 6 ms 15964 KB Output is correct
5 Correct 6 ms 15964 KB Output is correct
6 Correct 6 ms 15964 KB Output is correct
7 Correct 6 ms 15964 KB Output is correct
8 Correct 6 ms 15964 KB Output is correct
9 Correct 6 ms 15964 KB Output is correct
10 Correct 6 ms 15964 KB Output is correct
11 Correct 7 ms 16220 KB Output is correct
12 Correct 8 ms 16236 KB Output is correct
13 Correct 8 ms 16220 KB Output is correct
14 Correct 9 ms 16248 KB Output is correct
15 Correct 8 ms 16220 KB Output is correct
16 Correct 8 ms 16220 KB Output is correct
17 Correct 8 ms 16220 KB Output is correct
18 Correct 8 ms 16220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 682 ms 50260 KB Output is correct
2 Correct 755 ms 50772 KB Output is correct
3 Correct 701 ms 50740 KB Output is correct
4 Correct 703 ms 50720 KB Output is correct
5 Correct 581 ms 42576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 19328 KB Output is correct
2 Correct 66 ms 19368 KB Output is correct
3 Correct 53 ms 18208 KB Output is correct
4 Correct 55 ms 18260 KB Output is correct
5 Correct 54 ms 18304 KB Output is correct
6 Correct 49 ms 18212 KB Output is correct
7 Correct 52 ms 18252 KB Output is correct
8 Correct 49 ms 18004 KB Output is correct
9 Correct 30 ms 17744 KB Output is correct
10 Correct 49 ms 18004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 15960 KB Output is correct
2 Correct 6 ms 15964 KB Output is correct
3 Correct 6 ms 15904 KB Output is correct
4 Correct 6 ms 15964 KB Output is correct
5 Correct 6 ms 15964 KB Output is correct
6 Correct 6 ms 15964 KB Output is correct
7 Correct 6 ms 15964 KB Output is correct
8 Correct 6 ms 15964 KB Output is correct
9 Correct 6 ms 15964 KB Output is correct
10 Correct 6 ms 15964 KB Output is correct
11 Correct 7 ms 16220 KB Output is correct
12 Correct 8 ms 16236 KB Output is correct
13 Correct 8 ms 16220 KB Output is correct
14 Correct 9 ms 16248 KB Output is correct
15 Correct 8 ms 16220 KB Output is correct
16 Correct 8 ms 16220 KB Output is correct
17 Correct 8 ms 16220 KB Output is correct
18 Correct 8 ms 16220 KB Output is correct
19 Correct 135 ms 23616 KB Output is correct
20 Correct 136 ms 23544 KB Output is correct
21 Correct 128 ms 23636 KB Output is correct
22 Correct 135 ms 23632 KB Output is correct
23 Correct 128 ms 23632 KB Output is correct
24 Correct 107 ms 21220 KB Output is correct
25 Correct 105 ms 21332 KB Output is correct
26 Correct 111 ms 21536 KB Output is correct
27 Correct 117 ms 21592 KB Output is correct
28 Correct 114 ms 21496 KB Output is correct
29 Correct 117 ms 21624 KB Output is correct
30 Correct 118 ms 21580 KB Output is correct
31 Correct 117 ms 21672 KB Output is correct
32 Correct 125 ms 21600 KB Output is correct
33 Correct 117 ms 21504 KB Output is correct
34 Correct 100 ms 21280 KB Output is correct
35 Correct 97 ms 21304 KB Output is correct
36 Correct 102 ms 21332 KB Output is correct
37 Correct 99 ms 21332 KB Output is correct
38 Correct 100 ms 21328 KB Output is correct
39 Correct 105 ms 21588 KB Output is correct
40 Correct 85 ms 20208 KB Output is correct
41 Correct 104 ms 20560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 15960 KB Output is correct
2 Correct 6 ms 15964 KB Output is correct
3 Correct 6 ms 15904 KB Output is correct
4 Correct 6 ms 15964 KB Output is correct
5 Correct 6 ms 15964 KB Output is correct
6 Correct 6 ms 15964 KB Output is correct
7 Correct 6 ms 15964 KB Output is correct
8 Correct 6 ms 15964 KB Output is correct
9 Correct 6 ms 15964 KB Output is correct
10 Correct 6 ms 15964 KB Output is correct
11 Correct 7 ms 16220 KB Output is correct
12 Correct 8 ms 16236 KB Output is correct
13 Correct 8 ms 16220 KB Output is correct
14 Correct 9 ms 16248 KB Output is correct
15 Correct 8 ms 16220 KB Output is correct
16 Correct 8 ms 16220 KB Output is correct
17 Correct 8 ms 16220 KB Output is correct
18 Correct 8 ms 16220 KB Output is correct
19 Correct 682 ms 50260 KB Output is correct
20 Correct 755 ms 50772 KB Output is correct
21 Correct 701 ms 50740 KB Output is correct
22 Correct 703 ms 50720 KB Output is correct
23 Correct 581 ms 42576 KB Output is correct
24 Correct 63 ms 19328 KB Output is correct
25 Correct 66 ms 19368 KB Output is correct
26 Correct 53 ms 18208 KB Output is correct
27 Correct 55 ms 18260 KB Output is correct
28 Correct 54 ms 18304 KB Output is correct
29 Correct 49 ms 18212 KB Output is correct
30 Correct 52 ms 18252 KB Output is correct
31 Correct 49 ms 18004 KB Output is correct
32 Correct 30 ms 17744 KB Output is correct
33 Correct 49 ms 18004 KB Output is correct
34 Correct 135 ms 23616 KB Output is correct
35 Correct 136 ms 23544 KB Output is correct
36 Correct 128 ms 23636 KB Output is correct
37 Correct 135 ms 23632 KB Output is correct
38 Correct 128 ms 23632 KB Output is correct
39 Correct 107 ms 21220 KB Output is correct
40 Correct 105 ms 21332 KB Output is correct
41 Correct 111 ms 21536 KB Output is correct
42 Correct 117 ms 21592 KB Output is correct
43 Correct 114 ms 21496 KB Output is correct
44 Correct 117 ms 21624 KB Output is correct
45 Correct 118 ms 21580 KB Output is correct
46 Correct 117 ms 21672 KB Output is correct
47 Correct 125 ms 21600 KB Output is correct
48 Correct 117 ms 21504 KB Output is correct
49 Correct 100 ms 21280 KB Output is correct
50 Correct 97 ms 21304 KB Output is correct
51 Correct 102 ms 21332 KB Output is correct
52 Correct 99 ms 21332 KB Output is correct
53 Correct 100 ms 21328 KB Output is correct
54 Correct 105 ms 21588 KB Output is correct
55 Correct 85 ms 20208 KB Output is correct
56 Correct 104 ms 20560 KB Output is correct
57 Correct 719 ms 50732 KB Output is correct
58 Correct 746 ms 59476 KB Output is correct
59 Correct 736 ms 59468 KB Output is correct
60 Correct 748 ms 59336 KB Output is correct
61 Correct 731 ms 59464 KB Output is correct
62 Correct 710 ms 59440 KB Output is correct
63 Correct 513 ms 50000 KB Output is correct
64 Correct 515 ms 49812 KB Output is correct
65 Correct 597 ms 51192 KB Output is correct
66 Correct 589 ms 51052 KB Output is correct
67 Correct 604 ms 51292 KB Output is correct
68 Correct 592 ms 51280 KB Output is correct
69 Correct 584 ms 51144 KB Output is correct
70 Correct 585 ms 51284 KB Output is correct
71 Correct 598 ms 51448 KB Output is correct
72 Correct 595 ms 42880 KB Output is correct
73 Correct 538 ms 47524 KB Output is correct
74 Correct 494 ms 49640 KB Output is correct
75 Correct 538 ms 48976 KB Output is correct
76 Correct 508 ms 48820 KB Output is correct
77 Correct 493 ms 48980 KB Output is correct
78 Correct 573 ms 49276 KB Output is correct
79 Correct 423 ms 41460 KB Output is correct
80 Correct 524 ms 44592 KB Output is correct