#include <bits/stdc++.h>
using std::vector;
using std::array;
using std::pair;
using std::tuple;
using ll = long long;
template <class T>
constexpr T infty = std::numeric_limits<T>::max() / 2;
class RangeMin {
int size;
vector<int> data;
public:
explicit RangeMin(const int n, const int x) : size(n), data(2 * n, x) {}
void setmin(int i, const int x) {
i += size;
while (i > 0) {
data[i] = std::min(data[i], x);
i >>= 1;
}
}
int fold(int l, int r) const {
l += size, r += size;
int ret = infty<int>;
while (l < r) {
if (l & 1) ret = std::min(ret, data[l++]);
if (r & 1) ret = std::min(ret, data[--r]);
l >>= 1, r >>= 1;
}
return ret;
}
};
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int N, Q;
std::cin >> N >> Q;
vector<int> W(N);
for (auto& x : W) {
std::cin >> x;
}
vector<int> L(Q), R(Q), K(Q);
for (int i = 0; i < Q; ++i) {
std::cin >> L[i] >> R[i] >> K[i];
L[i] -= 1;
}
vector<tuple<int, int, int>> event;
vector<int> stack;
for (int i = N - 1; i >= 0; --i) {
while (!stack.empty() and W[stack.back()] < W[i]) {
event.emplace_back(W[i] + W[stack.back()], i, stack.back());
stack.pop_back();
}
stack.push_back(i);
}
vector<int> idx(Q);
std::iota(idx.begin(), idx.end(), 0);
std::sort(idx.begin(), idx.end(), [&](const int i, const int j) {
return K[i] > K[j];
});
std::sort(event.begin(), event.end());
RangeMin rmq(N, N);
vector<int> ans(Q);
for (const int q : idx) {
while (!event.empty() and K[q] < std::get<0>(event.back())) {
const auto [w, i, j] = event.back();
event.pop_back();
rmq.setmin(i, j);
}
ans[q] = rmq.fold(L[q], R[q]) >= R[q];
}
for (const int x : ans) {
std::cout << x << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
584 KB |
Output is correct |
13 |
Correct |
3 ms |
568 KB |
Output is correct |
14 |
Correct |
4 ms |
596 KB |
Output is correct |
15 |
Correct |
6 ms |
612 KB |
Output is correct |
16 |
Correct |
4 ms |
596 KB |
Output is correct |
17 |
Correct |
3 ms |
596 KB |
Output is correct |
18 |
Correct |
3 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1012 ms |
52696 KB |
Output is correct |
2 |
Correct |
1058 ms |
78232 KB |
Output is correct |
3 |
Correct |
1018 ms |
78224 KB |
Output is correct |
4 |
Correct |
993 ms |
78264 KB |
Output is correct |
5 |
Correct |
831 ms |
70652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
6756 KB |
Output is correct |
2 |
Correct |
101 ms |
6740 KB |
Output is correct |
3 |
Correct |
60 ms |
6200 KB |
Output is correct |
4 |
Correct |
57 ms |
6100 KB |
Output is correct |
5 |
Correct |
55 ms |
6088 KB |
Output is correct |
6 |
Correct |
54 ms |
6024 KB |
Output is correct |
7 |
Correct |
54 ms |
6012 KB |
Output is correct |
8 |
Correct |
56 ms |
6284 KB |
Output is correct |
9 |
Correct |
44 ms |
3796 KB |
Output is correct |
10 |
Correct |
63 ms |
6420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
584 KB |
Output is correct |
13 |
Correct |
3 ms |
568 KB |
Output is correct |
14 |
Correct |
4 ms |
596 KB |
Output is correct |
15 |
Correct |
6 ms |
612 KB |
Output is correct |
16 |
Correct |
4 ms |
596 KB |
Output is correct |
17 |
Correct |
3 ms |
596 KB |
Output is correct |
18 |
Correct |
3 ms |
596 KB |
Output is correct |
19 |
Correct |
176 ms |
15820 KB |
Output is correct |
20 |
Correct |
186 ms |
15900 KB |
Output is correct |
21 |
Correct |
187 ms |
15732 KB |
Output is correct |
22 |
Correct |
160 ms |
15652 KB |
Output is correct |
23 |
Correct |
181 ms |
15708 KB |
Output is correct |
24 |
Correct |
173 ms |
14236 KB |
Output is correct |
25 |
Correct |
135 ms |
14188 KB |
Output is correct |
26 |
Correct |
146 ms |
14404 KB |
Output is correct |
27 |
Correct |
146 ms |
14388 KB |
Output is correct |
28 |
Correct |
145 ms |
14408 KB |
Output is correct |
29 |
Correct |
174 ms |
14432 KB |
Output is correct |
30 |
Correct |
145 ms |
14392 KB |
Output is correct |
31 |
Correct |
154 ms |
14444 KB |
Output is correct |
32 |
Correct |
154 ms |
14444 KB |
Output is correct |
33 |
Correct |
172 ms |
14388 KB |
Output is correct |
34 |
Correct |
117 ms |
14104 KB |
Output is correct |
35 |
Correct |
121 ms |
14016 KB |
Output is correct |
36 |
Correct |
137 ms |
13920 KB |
Output is correct |
37 |
Correct |
131 ms |
13804 KB |
Output is correct |
38 |
Correct |
113 ms |
14112 KB |
Output is correct |
39 |
Correct |
144 ms |
13752 KB |
Output is correct |
40 |
Correct |
120 ms |
11660 KB |
Output is correct |
41 |
Correct |
137 ms |
13468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
584 KB |
Output is correct |
13 |
Correct |
3 ms |
568 KB |
Output is correct |
14 |
Correct |
4 ms |
596 KB |
Output is correct |
15 |
Correct |
6 ms |
612 KB |
Output is correct |
16 |
Correct |
4 ms |
596 KB |
Output is correct |
17 |
Correct |
3 ms |
596 KB |
Output is correct |
18 |
Correct |
3 ms |
596 KB |
Output is correct |
19 |
Correct |
1012 ms |
52696 KB |
Output is correct |
20 |
Correct |
1058 ms |
78232 KB |
Output is correct |
21 |
Correct |
1018 ms |
78224 KB |
Output is correct |
22 |
Correct |
993 ms |
78264 KB |
Output is correct |
23 |
Correct |
831 ms |
70652 KB |
Output is correct |
24 |
Correct |
68 ms |
6756 KB |
Output is correct |
25 |
Correct |
101 ms |
6740 KB |
Output is correct |
26 |
Correct |
60 ms |
6200 KB |
Output is correct |
27 |
Correct |
57 ms |
6100 KB |
Output is correct |
28 |
Correct |
55 ms |
6088 KB |
Output is correct |
29 |
Correct |
54 ms |
6024 KB |
Output is correct |
30 |
Correct |
54 ms |
6012 KB |
Output is correct |
31 |
Correct |
56 ms |
6284 KB |
Output is correct |
32 |
Correct |
44 ms |
3796 KB |
Output is correct |
33 |
Correct |
63 ms |
6420 KB |
Output is correct |
34 |
Correct |
176 ms |
15820 KB |
Output is correct |
35 |
Correct |
186 ms |
15900 KB |
Output is correct |
36 |
Correct |
187 ms |
15732 KB |
Output is correct |
37 |
Correct |
160 ms |
15652 KB |
Output is correct |
38 |
Correct |
181 ms |
15708 KB |
Output is correct |
39 |
Correct |
173 ms |
14236 KB |
Output is correct |
40 |
Correct |
135 ms |
14188 KB |
Output is correct |
41 |
Correct |
146 ms |
14404 KB |
Output is correct |
42 |
Correct |
146 ms |
14388 KB |
Output is correct |
43 |
Correct |
145 ms |
14408 KB |
Output is correct |
44 |
Correct |
174 ms |
14432 KB |
Output is correct |
45 |
Correct |
145 ms |
14392 KB |
Output is correct |
46 |
Correct |
154 ms |
14444 KB |
Output is correct |
47 |
Correct |
154 ms |
14444 KB |
Output is correct |
48 |
Correct |
172 ms |
14388 KB |
Output is correct |
49 |
Correct |
117 ms |
14104 KB |
Output is correct |
50 |
Correct |
121 ms |
14016 KB |
Output is correct |
51 |
Correct |
137 ms |
13920 KB |
Output is correct |
52 |
Correct |
131 ms |
13804 KB |
Output is correct |
53 |
Correct |
113 ms |
14112 KB |
Output is correct |
54 |
Correct |
144 ms |
13752 KB |
Output is correct |
55 |
Correct |
120 ms |
11660 KB |
Output is correct |
56 |
Correct |
137 ms |
13468 KB |
Output is correct |
57 |
Correct |
1085 ms |
78888 KB |
Output is correct |
58 |
Correct |
1089 ms |
78936 KB |
Output is correct |
59 |
Correct |
1095 ms |
78836 KB |
Output is correct |
60 |
Correct |
1110 ms |
78784 KB |
Output is correct |
61 |
Correct |
1133 ms |
78756 KB |
Output is correct |
62 |
Correct |
1114 ms |
78768 KB |
Output is correct |
63 |
Correct |
799 ms |
69328 KB |
Output is correct |
64 |
Correct |
820 ms |
69372 KB |
Output is correct |
65 |
Correct |
863 ms |
70936 KB |
Output is correct |
66 |
Correct |
862 ms |
71152 KB |
Output is correct |
67 |
Correct |
955 ms |
70976 KB |
Output is correct |
68 |
Correct |
907 ms |
70724 KB |
Output is correct |
69 |
Correct |
938 ms |
71228 KB |
Output is correct |
70 |
Correct |
924 ms |
71216 KB |
Output is correct |
71 |
Correct |
1022 ms |
71208 KB |
Output is correct |
72 |
Correct |
924 ms |
71196 KB |
Output is correct |
73 |
Correct |
686 ms |
67720 KB |
Output is correct |
74 |
Correct |
786 ms |
68336 KB |
Output is correct |
75 |
Correct |
694 ms |
67376 KB |
Output is correct |
76 |
Correct |
616 ms |
67432 KB |
Output is correct |
77 |
Correct |
658 ms |
67428 KB |
Output is correct |
78 |
Correct |
927 ms |
68736 KB |
Output is correct |
79 |
Correct |
599 ms |
54412 KB |
Output is correct |
80 |
Correct |
803 ms |
68244 KB |
Output is correct |