답안 #717770

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
717770 2023-04-02T13:43:12 Z TS_2392 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1393 ms 97724 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 3;
int n, numq, a[N], st[N * 4], prv[N];
bool res[N];
vector< array<int, 3> > qrywithR[N];
void update(int id, int L, int R, int p, int v){
    if(L == R){
        st[id] = max(st[id], v);
        return;
    }
    int mid = L + R >> 1;
    if(p <= mid) update(id << 1, L, mid, p, v);
    else update(id << 1 | 1, mid + 1, R, p, v);
    st[id] = max(st[id << 1], st[id << 1 | 1]);
}
int get_max(int id, int L, int R, int Lq, int Rq){
    if(R < Lq || Rq < L) return 0;
    if(Lq <= L && R <= Rq) return st[id];
    int mid = L + R >> 1;
    return max(get_max(id << 1, L, mid, Lq, Rq), get_max(id << 1 | 1, mid + 1, R, Lq, Rq));
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin >> n >> numq;
    a[0] = 1e9 + 3;
    for(int i = 1, j; i <= n; ++i){
        cin >> a[i]; j = i - 1;
        while(a[j] <= a[i]) j = prv[j];
        prv[i] = j;
    }
    for(int i = 1; i <= numq; ++i){
        int l, r, k;
        cin >> l >> r >> k;
        qrywithR[r].push_back({l, k, i});
    }
    for(int i = 1; i <= n; ++i){
        update(1, 0, n, prv[i], a[i] + a[prv[i]]);
        for(auto &x : qrywithR[i]){
            int j = x[0], k = x[1], id = x[2];
            if(get_max(1, 0, n, j, i) <= k) res[id] = 1;
            else res[id] = 0;
        }
    }
    for(int i = 1; i <= numq; ++i){
        cout << res[i] << '\n';
    }
    return 0;
}

Compilation message

sortbooks.cpp: In function 'void update(int, int, int, int, int)':
sortbooks.cpp:12:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   12 |     int mid = L + R >> 1;
      |               ~~^~~
sortbooks.cpp: In function 'int get_max(int, int, int, int, int)':
sortbooks.cpp:20:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   20 |     int mid = L + R >> 1;
      |               ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 13 ms 23808 KB Output is correct
4 Correct 15 ms 23764 KB Output is correct
5 Correct 13 ms 23764 KB Output is correct
6 Correct 14 ms 23820 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 13 ms 23820 KB Output is correct
9 Correct 12 ms 23812 KB Output is correct
10 Correct 12 ms 23860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 13 ms 23808 KB Output is correct
4 Correct 15 ms 23764 KB Output is correct
5 Correct 13 ms 23764 KB Output is correct
6 Correct 14 ms 23820 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 13 ms 23820 KB Output is correct
9 Correct 12 ms 23812 KB Output is correct
10 Correct 12 ms 23860 KB Output is correct
11 Correct 16 ms 23948 KB Output is correct
12 Correct 15 ms 24056 KB Output is correct
13 Correct 15 ms 24020 KB Output is correct
14 Correct 17 ms 24208 KB Output is correct
15 Correct 18 ms 24148 KB Output is correct
16 Correct 16 ms 24080 KB Output is correct
17 Correct 16 ms 24112 KB Output is correct
18 Correct 16 ms 24016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1264 ms 96560 KB Output is correct
2 Correct 1316 ms 97568 KB Output is correct
3 Correct 1250 ms 97484 KB Output is correct
4 Correct 1256 ms 97440 KB Output is correct
5 Correct 1260 ms 89336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 29952 KB Output is correct
2 Correct 93 ms 29708 KB Output is correct
3 Correct 89 ms 28856 KB Output is correct
4 Correct 108 ms 28940 KB Output is correct
5 Correct 104 ms 29032 KB Output is correct
6 Correct 84 ms 28384 KB Output is correct
7 Correct 76 ms 28476 KB Output is correct
8 Correct 86 ms 28528 KB Output is correct
9 Correct 51 ms 26880 KB Output is correct
10 Correct 93 ms 28548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 13 ms 23808 KB Output is correct
4 Correct 15 ms 23764 KB Output is correct
5 Correct 13 ms 23764 KB Output is correct
6 Correct 14 ms 23820 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 13 ms 23820 KB Output is correct
9 Correct 12 ms 23812 KB Output is correct
10 Correct 12 ms 23860 KB Output is correct
11 Correct 16 ms 23948 KB Output is correct
12 Correct 15 ms 24056 KB Output is correct
13 Correct 15 ms 24020 KB Output is correct
14 Correct 17 ms 24208 KB Output is correct
15 Correct 18 ms 24148 KB Output is correct
16 Correct 16 ms 24080 KB Output is correct
17 Correct 16 ms 24112 KB Output is correct
18 Correct 16 ms 24016 KB Output is correct
19 Correct 251 ms 38860 KB Output is correct
20 Correct 232 ms 38760 KB Output is correct
21 Correct 191 ms 38148 KB Output is correct
22 Correct 196 ms 38196 KB Output is correct
23 Correct 208 ms 38172 KB Output is correct
24 Correct 170 ms 35904 KB Output is correct
25 Correct 210 ms 36208 KB Output is correct
26 Correct 192 ms 36404 KB Output is correct
27 Correct 221 ms 36448 KB Output is correct
28 Correct 210 ms 36432 KB Output is correct
29 Correct 204 ms 36856 KB Output is correct
30 Correct 213 ms 36844 KB Output is correct
31 Correct 214 ms 36768 KB Output is correct
32 Correct 267 ms 36816 KB Output is correct
33 Correct 221 ms 36816 KB Output is correct
34 Correct 166 ms 35548 KB Output is correct
35 Correct 183 ms 35508 KB Output is correct
36 Correct 183 ms 35440 KB Output is correct
37 Correct 170 ms 35392 KB Output is correct
38 Correct 179 ms 35512 KB Output is correct
39 Correct 190 ms 35764 KB Output is correct
40 Correct 162 ms 33480 KB Output is correct
41 Correct 183 ms 34752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 13 ms 23808 KB Output is correct
4 Correct 15 ms 23764 KB Output is correct
5 Correct 13 ms 23764 KB Output is correct
6 Correct 14 ms 23820 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 13 ms 23820 KB Output is correct
9 Correct 12 ms 23812 KB Output is correct
10 Correct 12 ms 23860 KB Output is correct
11 Correct 16 ms 23948 KB Output is correct
12 Correct 15 ms 24056 KB Output is correct
13 Correct 15 ms 24020 KB Output is correct
14 Correct 17 ms 24208 KB Output is correct
15 Correct 18 ms 24148 KB Output is correct
16 Correct 16 ms 24080 KB Output is correct
17 Correct 16 ms 24112 KB Output is correct
18 Correct 16 ms 24016 KB Output is correct
19 Correct 1264 ms 96560 KB Output is correct
20 Correct 1316 ms 97568 KB Output is correct
21 Correct 1250 ms 97484 KB Output is correct
22 Correct 1256 ms 97440 KB Output is correct
23 Correct 1260 ms 89336 KB Output is correct
24 Correct 101 ms 29952 KB Output is correct
25 Correct 93 ms 29708 KB Output is correct
26 Correct 89 ms 28856 KB Output is correct
27 Correct 108 ms 28940 KB Output is correct
28 Correct 104 ms 29032 KB Output is correct
29 Correct 84 ms 28384 KB Output is correct
30 Correct 76 ms 28476 KB Output is correct
31 Correct 86 ms 28528 KB Output is correct
32 Correct 51 ms 26880 KB Output is correct
33 Correct 93 ms 28548 KB Output is correct
34 Correct 251 ms 38860 KB Output is correct
35 Correct 232 ms 38760 KB Output is correct
36 Correct 191 ms 38148 KB Output is correct
37 Correct 196 ms 38196 KB Output is correct
38 Correct 208 ms 38172 KB Output is correct
39 Correct 170 ms 35904 KB Output is correct
40 Correct 210 ms 36208 KB Output is correct
41 Correct 192 ms 36404 KB Output is correct
42 Correct 221 ms 36448 KB Output is correct
43 Correct 210 ms 36432 KB Output is correct
44 Correct 204 ms 36856 KB Output is correct
45 Correct 213 ms 36844 KB Output is correct
46 Correct 214 ms 36768 KB Output is correct
47 Correct 267 ms 36816 KB Output is correct
48 Correct 221 ms 36816 KB Output is correct
49 Correct 166 ms 35548 KB Output is correct
50 Correct 183 ms 35508 KB Output is correct
51 Correct 183 ms 35440 KB Output is correct
52 Correct 170 ms 35392 KB Output is correct
53 Correct 179 ms 35512 KB Output is correct
54 Correct 190 ms 35764 KB Output is correct
55 Correct 162 ms 33480 KB Output is correct
56 Correct 183 ms 34752 KB Output is correct
57 Correct 1393 ms 97680 KB Output is correct
58 Correct 1314 ms 97724 KB Output is correct
59 Correct 1226 ms 96108 KB Output is correct
60 Correct 1214 ms 96028 KB Output is correct
61 Correct 1232 ms 96240 KB Output is correct
62 Correct 1226 ms 96044 KB Output is correct
63 Correct 940 ms 84732 KB Output is correct
64 Correct 893 ms 84764 KB Output is correct
65 Correct 1118 ms 87676 KB Output is correct
66 Correct 1109 ms 87856 KB Output is correct
67 Correct 1178 ms 87824 KB Output is correct
68 Correct 1157 ms 89264 KB Output is correct
69 Correct 1180 ms 89556 KB Output is correct
70 Correct 1165 ms 88832 KB Output is correct
71 Correct 1242 ms 88904 KB Output is correct
72 Correct 1213 ms 89044 KB Output is correct
73 Correct 859 ms 80436 KB Output is correct
74 Correct 828 ms 81360 KB Output is correct
75 Correct 802 ms 80416 KB Output is correct
76 Correct 793 ms 80720 KB Output is correct
77 Correct 797 ms 80344 KB Output is correct
78 Correct 1038 ms 84272 KB Output is correct
79 Correct 757 ms 70644 KB Output is correct
80 Correct 929 ms 78644 KB Output is correct