답안 #1111631

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1111631 2024-11-12T12:06:50 Z Pekiban Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
2249 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;
vector<int> st[4*N];
int mx[4*N], n;
void build(vector<int> &a, int i = 1, int l2 = 1, int r2 = n) {
    if (l2 == r2) {
        st[i]= {a[l2]};
        mx[i] = 0;
        return;
    }
    int m2 = (l2 + r2)/2;
    build(a, 2*i, l2, m2);
    build(a, 2*i+1, m2+1, r2);
    st[i].resize(r2 - l2 + 1);
    merge(st[2*i].begin(), st[2*i].end(), st[2*i+1].begin(), st[2*i+1].end(), st[i].begin());
    int id = upper_bound(st[2*i+1].begin(), st[2*i+1].end(), st[2*i].back()-1) - st[2*i+1].begin();
    if (!id)    mx[i] = max(mx[2*i], mx[2*i+1]);
    else {
        mx[i] = max({mx[2*i], mx[2*i+1], st[2*i].back() + st[2*i+1][id-1]});
    }
}
int M = 0, MS = 0;
void qry(int l, int r, int i = 1, int l2 = 1, int r2 = n) {
    if (l <= l2 && r2 <= r) {
        int id = upper_bound(st[i].begin(), st[i].end(), M-1) - st[i].begin();
        MS = max(MS, mx[i]);
        if (id) MS = max({MS, M + st[i][id-1]});
        M = max(M, st[i].back());
        return;
    }
    int m2 = (l2 + r2)/2;
    if (l <= m2)    qry(l, r, 2*i, l2, m2);
    if (m2 +1 <= r) qry(l, r, 2*i+1, m2+1, r2);   
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int m;
    cin >> n >> m;
    vector<int> a(n+1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    build(a);
    while (m--) {
        int l, r, k;
        cin >> l >> r >> k;
        M = 0, MS = 0;
        qry(l, r);
        cout << (MS <= k) << '\n'; 
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 95312 KB Output is correct
2 Correct 17 ms 95312 KB Output is correct
3 Correct 16 ms 95312 KB Output is correct
4 Correct 16 ms 95324 KB Output is correct
5 Correct 17 ms 95312 KB Output is correct
6 Correct 17 ms 95508 KB Output is correct
7 Correct 16 ms 95312 KB Output is correct
8 Correct 16 ms 95560 KB Output is correct
9 Correct 16 ms 95312 KB Output is correct
10 Correct 18 ms 95312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 95312 KB Output is correct
2 Correct 17 ms 95312 KB Output is correct
3 Correct 16 ms 95312 KB Output is correct
4 Correct 16 ms 95324 KB Output is correct
5 Correct 17 ms 95312 KB Output is correct
6 Correct 17 ms 95508 KB Output is correct
7 Correct 16 ms 95312 KB Output is correct
8 Correct 16 ms 95560 KB Output is correct
9 Correct 16 ms 95312 KB Output is correct
10 Correct 18 ms 95312 KB Output is correct
11 Correct 18 ms 95736 KB Output is correct
12 Correct 26 ms 96080 KB Output is correct
13 Correct 19 ms 96080 KB Output is correct
14 Correct 26 ms 96500 KB Output is correct
15 Correct 20 ms 96080 KB Output is correct
16 Correct 19 ms 96080 KB Output is correct
17 Correct 19 ms 95824 KB Output is correct
18 Correct 19 ms 96080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1969 ms 239296 KB Output is correct
2 Correct 2249 ms 260480 KB Output is correct
3 Correct 2229 ms 248416 KB Output is correct
4 Correct 2099 ms 248616 KB Output is correct
5 Correct 1636 ms 248648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 144 ms 109640 KB Output is correct
2 Correct 130 ms 111680 KB Output is correct
3 Correct 139 ms 111688 KB Output is correct
4 Correct 135 ms 111696 KB Output is correct
5 Correct 132 ms 111688 KB Output is correct
6 Correct 106 ms 111696 KB Output is correct
7 Correct 97 ms 111432 KB Output is correct
8 Correct 94 ms 111432 KB Output is correct
9 Correct 43 ms 96840 KB Output is correct
10 Correct 96 ms 111432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 95312 KB Output is correct
2 Correct 17 ms 95312 KB Output is correct
3 Correct 16 ms 95312 KB Output is correct
4 Correct 16 ms 95324 KB Output is correct
5 Correct 17 ms 95312 KB Output is correct
6 Correct 17 ms 95508 KB Output is correct
7 Correct 16 ms 95312 KB Output is correct
8 Correct 16 ms 95560 KB Output is correct
9 Correct 16 ms 95312 KB Output is correct
10 Correct 18 ms 95312 KB Output is correct
11 Correct 18 ms 95736 KB Output is correct
12 Correct 26 ms 96080 KB Output is correct
13 Correct 19 ms 96080 KB Output is correct
14 Correct 26 ms 96500 KB Output is correct
15 Correct 20 ms 96080 KB Output is correct
16 Correct 19 ms 96080 KB Output is correct
17 Correct 19 ms 95824 KB Output is correct
18 Correct 19 ms 96080 KB Output is correct
19 Correct 306 ms 129100 KB Output is correct
20 Correct 308 ms 129088 KB Output is correct
21 Correct 282 ms 128900 KB Output is correct
22 Correct 261 ms 128840 KB Output is correct
23 Correct 263 ms 128840 KB Output is correct
24 Correct 236 ms 128840 KB Output is correct
25 Correct 209 ms 128840 KB Output is correct
26 Correct 223 ms 129096 KB Output is correct
27 Correct 232 ms 128840 KB Output is correct
28 Correct 224 ms 129096 KB Output is correct
29 Correct 251 ms 129096 KB Output is correct
30 Correct 250 ms 129096 KB Output is correct
31 Correct 256 ms 129044 KB Output is correct
32 Correct 278 ms 129104 KB Output is correct
33 Correct 245 ms 128912 KB Output is correct
34 Correct 191 ms 128840 KB Output is correct
35 Correct 204 ms 128676 KB Output is correct
36 Correct 214 ms 128584 KB Output is correct
37 Correct 207 ms 128584 KB Output is correct
38 Correct 204 ms 128660 KB Output is correct
39 Correct 226 ms 127820 KB Output is correct
40 Correct 169 ms 118344 KB Output is correct
41 Correct 218 ms 127380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 95312 KB Output is correct
2 Correct 17 ms 95312 KB Output is correct
3 Correct 16 ms 95312 KB Output is correct
4 Correct 16 ms 95324 KB Output is correct
5 Correct 17 ms 95312 KB Output is correct
6 Correct 17 ms 95508 KB Output is correct
7 Correct 16 ms 95312 KB Output is correct
8 Correct 16 ms 95560 KB Output is correct
9 Correct 16 ms 95312 KB Output is correct
10 Correct 18 ms 95312 KB Output is correct
11 Correct 18 ms 95736 KB Output is correct
12 Correct 26 ms 96080 KB Output is correct
13 Correct 19 ms 96080 KB Output is correct
14 Correct 26 ms 96500 KB Output is correct
15 Correct 20 ms 96080 KB Output is correct
16 Correct 19 ms 96080 KB Output is correct
17 Correct 19 ms 95824 KB Output is correct
18 Correct 19 ms 96080 KB Output is correct
19 Correct 1969 ms 239296 KB Output is correct
20 Correct 2249 ms 260480 KB Output is correct
21 Correct 2229 ms 248416 KB Output is correct
22 Correct 2099 ms 248616 KB Output is correct
23 Correct 1636 ms 248648 KB Output is correct
24 Correct 144 ms 109640 KB Output is correct
25 Correct 130 ms 111680 KB Output is correct
26 Correct 139 ms 111688 KB Output is correct
27 Correct 135 ms 111696 KB Output is correct
28 Correct 132 ms 111688 KB Output is correct
29 Correct 106 ms 111696 KB Output is correct
30 Correct 97 ms 111432 KB Output is correct
31 Correct 94 ms 111432 KB Output is correct
32 Correct 43 ms 96840 KB Output is correct
33 Correct 96 ms 111432 KB Output is correct
34 Correct 306 ms 129100 KB Output is correct
35 Correct 308 ms 129088 KB Output is correct
36 Correct 282 ms 128900 KB Output is correct
37 Correct 261 ms 128840 KB Output is correct
38 Correct 263 ms 128840 KB Output is correct
39 Correct 236 ms 128840 KB Output is correct
40 Correct 209 ms 128840 KB Output is correct
41 Correct 223 ms 129096 KB Output is correct
42 Correct 232 ms 128840 KB Output is correct
43 Correct 224 ms 129096 KB Output is correct
44 Correct 251 ms 129096 KB Output is correct
45 Correct 250 ms 129096 KB Output is correct
46 Correct 256 ms 129044 KB Output is correct
47 Correct 278 ms 129104 KB Output is correct
48 Correct 245 ms 128912 KB Output is correct
49 Correct 191 ms 128840 KB Output is correct
50 Correct 204 ms 128676 KB Output is correct
51 Correct 214 ms 128584 KB Output is correct
52 Correct 207 ms 128584 KB Output is correct
53 Correct 204 ms 128660 KB Output is correct
54 Correct 226 ms 127820 KB Output is correct
55 Correct 169 ms 118344 KB Output is correct
56 Correct 218 ms 127380 KB Output is correct
57 Correct 2105 ms 262144 KB Output is correct
58 Correct 2120 ms 262144 KB Output is correct
59 Correct 1991 ms 262144 KB Output is correct
60 Correct 2170 ms 262144 KB Output is correct
61 Correct 2090 ms 262144 KB Output is correct
62 Correct 2071 ms 262144 KB Output is correct
63 Correct 1153 ms 262144 KB Output is correct
64 Correct 1103 ms 262144 KB Output is correct
65 Correct 1782 ms 262144 KB Output is correct
66 Correct 1763 ms 262144 KB Output is correct
67 Correct 1792 ms 262144 KB Output is correct
68 Correct 1813 ms 262144 KB Output is correct
69 Correct 1811 ms 262144 KB Output is correct
70 Correct 1772 ms 262144 KB Output is correct
71 Correct 1828 ms 262144 KB Output is correct
72 Correct 1776 ms 262144 KB Output is correct
73 Correct 1094 ms 262144 KB Output is correct
74 Correct 1116 ms 262144 KB Output is correct
75 Correct 1140 ms 262144 KB Output is correct
76 Correct 1159 ms 262144 KB Output is correct
77 Correct 1120 ms 262144 KB Output is correct
78 Correct 1573 ms 262144 KB Output is correct
79 Correct 961 ms 191764 KB Output is correct
80 Correct 1464 ms 262144 KB Output is correct