답안 #655208

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
655208 2022-11-03T14:43:55 Z stevancv Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1540 ms 110784 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e6 + 2;
const int inf = 2e9;
int st[4 * N];
void Add(int node, int l, int r, int x, int y) {
    smax(st[node], y);
    if (l == r) return;
    int mid = l + r >> 1;
    if (x <= mid) Add(2 * node, l, mid, x, y);
    else Add(2 * node + 1, mid + 1, r, x, y);
}
int Get(int node, int l, int r, int ql, int qr) {
    if (r < ql || qr < l) return 0;
    if (ql <= l && r <= qr) return st[node];
    int mid = l + r >> 1;
    return max(Get(2 * node, l, mid, ql, qr), Get(2 * node + 1, mid + 1, r, ql, qr));
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= 4 * n; i++) st[i] = -inf;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<vector<int>> qq(n);
    vector<int> l(m), r(m), x(m);
    for (int i = 0; i < m; i++) {
        cin >> l[i] >> r[i] >> x[i];
        l[i] -= 1; r[i] -= 1;
        qq[r[i]].push_back(i);
    }
    vector<int> ans(m);
    vector<int> v;
    for (int i = 0; i < n; i++) {
        while (!v.empty() && a[v.back()] <= a[i]) v.pop_back();
        if (!v.empty()) Add(1, 0, n - 1, v.back(), a[v.back()] + a[i]);
        for (int j : qq[i]) {
            int z = Get(1, 0, n - 1, l[j], i);
            if (z <= x[j]) ans[j]++;
        }
        v.push_back(i);
    }
    for (int i = 0; i < m; i++) cout << ans[i] << en;
    cout << en;
    return 0;
}

Compilation message

sortbooks.cpp: In function 'void Add(int, int, int, int, int)':
sortbooks.cpp:15:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   15 |     int mid = l + r >> 1;
      |               ~~^~~
sortbooks.cpp: In function 'int Get(int, int, int, int, int)':
sortbooks.cpp:22:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   22 |     int mid = l + r >> 1;
      |               ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 584 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 6 ms 852 KB Output is correct
15 Correct 4 ms 852 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 5 ms 724 KB Output is correct
18 Correct 4 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1300 ms 78904 KB Output is correct
2 Correct 1243 ms 79204 KB Output is correct
3 Correct 1249 ms 79144 KB Output is correct
4 Correct 1254 ms 79352 KB Output is correct
5 Correct 1137 ms 79312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 9304 KB Output is correct
2 Correct 77 ms 9168 KB Output is correct
3 Correct 81 ms 9748 KB Output is correct
4 Correct 76 ms 9912 KB Output is correct
5 Correct 95 ms 9952 KB Output is correct
6 Correct 59 ms 8748 KB Output is correct
7 Correct 59 ms 8744 KB Output is correct
8 Correct 65 ms 9500 KB Output is correct
9 Correct 35 ms 3844 KB Output is correct
10 Correct 65 ms 9544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 584 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 6 ms 852 KB Output is correct
15 Correct 4 ms 852 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 5 ms 724 KB Output is correct
18 Correct 4 ms 724 KB Output is correct
19 Correct 199 ms 22220 KB Output is correct
20 Correct 220 ms 22224 KB Output is correct
21 Correct 189 ms 20504 KB Output is correct
22 Correct 171 ms 20396 KB Output is correct
23 Correct 166 ms 20480 KB Output is correct
24 Correct 151 ms 20288 KB Output is correct
25 Correct 156 ms 20172 KB Output is correct
26 Correct 159 ms 21000 KB Output is correct
27 Correct 160 ms 21004 KB Output is correct
28 Correct 170 ms 21380 KB Output is correct
29 Correct 199 ms 22292 KB Output is correct
30 Correct 172 ms 22180 KB Output is correct
31 Correct 187 ms 22280 KB Output is correct
32 Correct 179 ms 22212 KB Output is correct
33 Correct 174 ms 22152 KB Output is correct
34 Correct 144 ms 19804 KB Output is correct
35 Correct 147 ms 19780 KB Output is correct
36 Correct 132 ms 19580 KB Output is correct
37 Correct 134 ms 19612 KB Output is correct
38 Correct 143 ms 19740 KB Output is correct
39 Correct 157 ms 20428 KB Output is correct
40 Correct 153 ms 16460 KB Output is correct
41 Correct 152 ms 20104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 584 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 6 ms 852 KB Output is correct
15 Correct 4 ms 852 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 5 ms 724 KB Output is correct
18 Correct 4 ms 724 KB Output is correct
19 Correct 1300 ms 78904 KB Output is correct
20 Correct 1243 ms 79204 KB Output is correct
21 Correct 1249 ms 79144 KB Output is correct
22 Correct 1254 ms 79352 KB Output is correct
23 Correct 1137 ms 79312 KB Output is correct
24 Correct 82 ms 9304 KB Output is correct
25 Correct 77 ms 9168 KB Output is correct
26 Correct 81 ms 9748 KB Output is correct
27 Correct 76 ms 9912 KB Output is correct
28 Correct 95 ms 9952 KB Output is correct
29 Correct 59 ms 8748 KB Output is correct
30 Correct 59 ms 8744 KB Output is correct
31 Correct 65 ms 9500 KB Output is correct
32 Correct 35 ms 3844 KB Output is correct
33 Correct 65 ms 9544 KB Output is correct
34 Correct 199 ms 22220 KB Output is correct
35 Correct 220 ms 22224 KB Output is correct
36 Correct 189 ms 20504 KB Output is correct
37 Correct 171 ms 20396 KB Output is correct
38 Correct 166 ms 20480 KB Output is correct
39 Correct 151 ms 20288 KB Output is correct
40 Correct 156 ms 20172 KB Output is correct
41 Correct 159 ms 21000 KB Output is correct
42 Correct 160 ms 21004 KB Output is correct
43 Correct 170 ms 21380 KB Output is correct
44 Correct 199 ms 22292 KB Output is correct
45 Correct 172 ms 22180 KB Output is correct
46 Correct 187 ms 22280 KB Output is correct
47 Correct 179 ms 22212 KB Output is correct
48 Correct 174 ms 22152 KB Output is correct
49 Correct 144 ms 19804 KB Output is correct
50 Correct 147 ms 19780 KB Output is correct
51 Correct 132 ms 19580 KB Output is correct
52 Correct 134 ms 19612 KB Output is correct
53 Correct 143 ms 19740 KB Output is correct
54 Correct 157 ms 20428 KB Output is correct
55 Correct 153 ms 16460 KB Output is correct
56 Correct 152 ms 20104 KB Output is correct
57 Correct 1280 ms 110728 KB Output is correct
58 Correct 1283 ms 110784 KB Output is correct
59 Correct 1196 ms 106568 KB Output is correct
60 Correct 1178 ms 106508 KB Output is correct
61 Correct 1161 ms 106532 KB Output is correct
62 Correct 1243 ms 106584 KB Output is correct
63 Correct 801 ms 98852 KB Output is correct
64 Correct 802 ms 98960 KB Output is correct
65 Correct 1084 ms 106112 KB Output is correct
66 Correct 1072 ms 105984 KB Output is correct
67 Correct 1125 ms 106348 KB Output is correct
68 Correct 1169 ms 110704 KB Output is correct
69 Correct 1237 ms 110660 KB Output is correct
70 Correct 1540 ms 110060 KB Output is correct
71 Correct 1234 ms 109944 KB Output is correct
72 Correct 1196 ms 109956 KB Output is correct
73 Correct 804 ms 96804 KB Output is correct
74 Correct 850 ms 97768 KB Output is correct
75 Correct 827 ms 96900 KB Output is correct
76 Correct 861 ms 97036 KB Output is correct
77 Correct 871 ms 96736 KB Output is correct
78 Correct 1107 ms 102724 KB Output is correct
79 Correct 765 ms 75124 KB Output is correct
80 Correct 1030 ms 100512 KB Output is correct