#include <bits/stdc++.h>
using namespace std;
#define Task ""
struct __Init__ {
__Init__() {
cin.tie(nullptr)->sync_with_stdio(false);
if (fopen(Task".inp", "r")) {
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout); }
}
} __init__;
using ll = long long;
#ifdef LOCAL
#define debug(x) cerr << "[" #x " = " << x << "]\n";
#else
#define debug(...)
#endif // LOCAL
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#define For(i, l, r) for (int i = (l); i <= (r); ++i)
#define Ford(i, r, l) for (int i = (r); i >= (l); --i)
#define Rep(i, n) For (i, 0, (n) - 1)
#define Repd(i, n) Ford (i, (n) - 1, 0)
template<class C> int isz(const C& c) { return c.size(); }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
constexpr int eps = 1e-9;
constexpr int inf = 1e9;
constexpr ll linf = 1e18;
// =============================================================================
constexpr int maxN = 1e6 + 5;
struct Query {
int r, k, id;
};
int n, nq;
int a[maxN];
vector<Query> q[maxN];
int ans[maxN];
int tree[maxN << 2];
#define m ((l + r) / 2)
#define tl (i << 1)
#define tr (i << 1 | 1)
void update(int p, int x, int i, int l, int r) {
if (p < l || r < p) return;
if (l == r) {
chmax(tree[i], x);
return;
}
update(p, x, tl, l, m);
update(p, x, tr, m + 1, r);
tree[i] = max(tree[tl], tree[tr]);
}
int get(int u, int v, int i, int l, int r) {
if (v < l || r < u) return 0;
if (u <= l && r <= v) return tree[i];
return max(get(u, v, tl, l, m), get(u, v, tr, m + 1, r));
}
#undef m
#undef tl
#undef tr
signed main() {
cin >> n >> nq;
For (i, 1, n) cin >> a[i];
For (i, 1, nq) {
int l, r, k; cin >> l >> r >> k;
q[l].push_back({r, k, i});
}
deque<int> dq;
Ford (i, n, 1) {
while (isz(dq) && a[i] > a[dq.front()]) {
update(dq.front(), a[i] + a[dq.front()], 1, 1, n);
dq.pop_front();
}
dq.push_front(i);
for (const auto& t : q[i]) {
ans[t.id] = get(i, t.r, 1, 1, n) <= t.k;
}
}
For (i, 1, nq) {
cout << ans[i] << '\n';
}
}
/*
*/
Compilation message
sortbooks.cpp: In constructor '__Init__::__Init__()':
sortbooks.cpp:11:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | freopen(Task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:12:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | freopen(Task".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
Output is correct |
2 |
Correct |
12 ms |
23688 KB |
Output is correct |
3 |
Correct |
13 ms |
23760 KB |
Output is correct |
4 |
Correct |
12 ms |
23812 KB |
Output is correct |
5 |
Correct |
12 ms |
23756 KB |
Output is correct |
6 |
Correct |
13 ms |
23844 KB |
Output is correct |
7 |
Correct |
12 ms |
23756 KB |
Output is correct |
8 |
Correct |
12 ms |
23840 KB |
Output is correct |
9 |
Correct |
12 ms |
23748 KB |
Output is correct |
10 |
Correct |
12 ms |
23808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
Output is correct |
2 |
Correct |
12 ms |
23688 KB |
Output is correct |
3 |
Correct |
13 ms |
23760 KB |
Output is correct |
4 |
Correct |
12 ms |
23812 KB |
Output is correct |
5 |
Correct |
12 ms |
23756 KB |
Output is correct |
6 |
Correct |
13 ms |
23844 KB |
Output is correct |
7 |
Correct |
12 ms |
23756 KB |
Output is correct |
8 |
Correct |
12 ms |
23840 KB |
Output is correct |
9 |
Correct |
12 ms |
23748 KB |
Output is correct |
10 |
Correct |
12 ms |
23808 KB |
Output is correct |
11 |
Correct |
16 ms |
23972 KB |
Output is correct |
12 |
Correct |
19 ms |
24004 KB |
Output is correct |
13 |
Correct |
15 ms |
24012 KB |
Output is correct |
14 |
Correct |
17 ms |
24096 KB |
Output is correct |
15 |
Correct |
17 ms |
24132 KB |
Output is correct |
16 |
Correct |
15 ms |
24012 KB |
Output is correct |
17 |
Correct |
15 ms |
24028 KB |
Output is correct |
18 |
Correct |
15 ms |
24016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1340 ms |
64680 KB |
Output is correct |
2 |
Correct |
1349 ms |
63728 KB |
Output is correct |
3 |
Correct |
1307 ms |
63564 KB |
Output is correct |
4 |
Correct |
1309 ms |
63692 KB |
Output is correct |
5 |
Correct |
1103 ms |
59656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
29116 KB |
Output is correct |
2 |
Correct |
97 ms |
29820 KB |
Output is correct |
3 |
Correct |
85 ms |
29200 KB |
Output is correct |
4 |
Correct |
82 ms |
29384 KB |
Output is correct |
5 |
Correct |
83 ms |
29436 KB |
Output is correct |
6 |
Correct |
76 ms |
28640 KB |
Output is correct |
7 |
Correct |
75 ms |
28632 KB |
Output is correct |
8 |
Correct |
83 ms |
29248 KB |
Output is correct |
9 |
Correct |
46 ms |
27164 KB |
Output is correct |
10 |
Correct |
80 ms |
29124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
Output is correct |
2 |
Correct |
12 ms |
23688 KB |
Output is correct |
3 |
Correct |
13 ms |
23760 KB |
Output is correct |
4 |
Correct |
12 ms |
23812 KB |
Output is correct |
5 |
Correct |
12 ms |
23756 KB |
Output is correct |
6 |
Correct |
13 ms |
23844 KB |
Output is correct |
7 |
Correct |
12 ms |
23756 KB |
Output is correct |
8 |
Correct |
12 ms |
23840 KB |
Output is correct |
9 |
Correct |
12 ms |
23748 KB |
Output is correct |
10 |
Correct |
12 ms |
23808 KB |
Output is correct |
11 |
Correct |
16 ms |
23972 KB |
Output is correct |
12 |
Correct |
19 ms |
24004 KB |
Output is correct |
13 |
Correct |
15 ms |
24012 KB |
Output is correct |
14 |
Correct |
17 ms |
24096 KB |
Output is correct |
15 |
Correct |
17 ms |
24132 KB |
Output is correct |
16 |
Correct |
15 ms |
24012 KB |
Output is correct |
17 |
Correct |
15 ms |
24028 KB |
Output is correct |
18 |
Correct |
15 ms |
24016 KB |
Output is correct |
19 |
Correct |
228 ms |
33352 KB |
Output is correct |
20 |
Correct |
221 ms |
38800 KB |
Output is correct |
21 |
Correct |
197 ms |
38144 KB |
Output is correct |
22 |
Correct |
198 ms |
38192 KB |
Output is correct |
23 |
Correct |
206 ms |
38256 KB |
Output is correct |
24 |
Correct |
161 ms |
36844 KB |
Output is correct |
25 |
Correct |
164 ms |
36896 KB |
Output is correct |
26 |
Correct |
173 ms |
37132 KB |
Output is correct |
27 |
Correct |
175 ms |
37108 KB |
Output is correct |
28 |
Correct |
192 ms |
37196 KB |
Output is correct |
29 |
Correct |
187 ms |
37620 KB |
Output is correct |
30 |
Correct |
191 ms |
37580 KB |
Output is correct |
31 |
Correct |
199 ms |
37712 KB |
Output is correct |
32 |
Correct |
188 ms |
37576 KB |
Output is correct |
33 |
Correct |
188 ms |
37640 KB |
Output is correct |
34 |
Correct |
160 ms |
35968 KB |
Output is correct |
35 |
Correct |
156 ms |
35976 KB |
Output is correct |
36 |
Correct |
146 ms |
35704 KB |
Output is correct |
37 |
Correct |
148 ms |
35724 KB |
Output is correct |
38 |
Correct |
152 ms |
35972 KB |
Output is correct |
39 |
Correct |
164 ms |
35880 KB |
Output is correct |
40 |
Correct |
139 ms |
34264 KB |
Output is correct |
41 |
Correct |
163 ms |
35708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
Output is correct |
2 |
Correct |
12 ms |
23688 KB |
Output is correct |
3 |
Correct |
13 ms |
23760 KB |
Output is correct |
4 |
Correct |
12 ms |
23812 KB |
Output is correct |
5 |
Correct |
12 ms |
23756 KB |
Output is correct |
6 |
Correct |
13 ms |
23844 KB |
Output is correct |
7 |
Correct |
12 ms |
23756 KB |
Output is correct |
8 |
Correct |
12 ms |
23840 KB |
Output is correct |
9 |
Correct |
12 ms |
23748 KB |
Output is correct |
10 |
Correct |
12 ms |
23808 KB |
Output is correct |
11 |
Correct |
16 ms |
23972 KB |
Output is correct |
12 |
Correct |
19 ms |
24004 KB |
Output is correct |
13 |
Correct |
15 ms |
24012 KB |
Output is correct |
14 |
Correct |
17 ms |
24096 KB |
Output is correct |
15 |
Correct |
17 ms |
24132 KB |
Output is correct |
16 |
Correct |
15 ms |
24012 KB |
Output is correct |
17 |
Correct |
15 ms |
24028 KB |
Output is correct |
18 |
Correct |
15 ms |
24016 KB |
Output is correct |
19 |
Correct |
1340 ms |
64680 KB |
Output is correct |
20 |
Correct |
1349 ms |
63728 KB |
Output is correct |
21 |
Correct |
1307 ms |
63564 KB |
Output is correct |
22 |
Correct |
1309 ms |
63692 KB |
Output is correct |
23 |
Correct |
1103 ms |
59656 KB |
Output is correct |
24 |
Correct |
106 ms |
29116 KB |
Output is correct |
25 |
Correct |
97 ms |
29820 KB |
Output is correct |
26 |
Correct |
85 ms |
29200 KB |
Output is correct |
27 |
Correct |
82 ms |
29384 KB |
Output is correct |
28 |
Correct |
83 ms |
29436 KB |
Output is correct |
29 |
Correct |
76 ms |
28640 KB |
Output is correct |
30 |
Correct |
75 ms |
28632 KB |
Output is correct |
31 |
Correct |
83 ms |
29248 KB |
Output is correct |
32 |
Correct |
46 ms |
27164 KB |
Output is correct |
33 |
Correct |
80 ms |
29124 KB |
Output is correct |
34 |
Correct |
228 ms |
33352 KB |
Output is correct |
35 |
Correct |
221 ms |
38800 KB |
Output is correct |
36 |
Correct |
197 ms |
38144 KB |
Output is correct |
37 |
Correct |
198 ms |
38192 KB |
Output is correct |
38 |
Correct |
206 ms |
38256 KB |
Output is correct |
39 |
Correct |
161 ms |
36844 KB |
Output is correct |
40 |
Correct |
164 ms |
36896 KB |
Output is correct |
41 |
Correct |
173 ms |
37132 KB |
Output is correct |
42 |
Correct |
175 ms |
37108 KB |
Output is correct |
43 |
Correct |
192 ms |
37196 KB |
Output is correct |
44 |
Correct |
187 ms |
37620 KB |
Output is correct |
45 |
Correct |
191 ms |
37580 KB |
Output is correct |
46 |
Correct |
199 ms |
37712 KB |
Output is correct |
47 |
Correct |
188 ms |
37576 KB |
Output is correct |
48 |
Correct |
188 ms |
37640 KB |
Output is correct |
49 |
Correct |
160 ms |
35968 KB |
Output is correct |
50 |
Correct |
156 ms |
35976 KB |
Output is correct |
51 |
Correct |
146 ms |
35704 KB |
Output is correct |
52 |
Correct |
148 ms |
35724 KB |
Output is correct |
53 |
Correct |
152 ms |
35972 KB |
Output is correct |
54 |
Correct |
164 ms |
35880 KB |
Output is correct |
55 |
Correct |
139 ms |
34264 KB |
Output is correct |
56 |
Correct |
163 ms |
35708 KB |
Output is correct |
57 |
Correct |
1343 ms |
97856 KB |
Output is correct |
58 |
Correct |
1323 ms |
97936 KB |
Output is correct |
59 |
Correct |
1234 ms |
95820 KB |
Output is correct |
60 |
Correct |
1242 ms |
95784 KB |
Output is correct |
61 |
Correct |
1286 ms |
95752 KB |
Output is correct |
62 |
Correct |
1251 ms |
95928 KB |
Output is correct |
63 |
Correct |
826 ms |
85300 KB |
Output is correct |
64 |
Correct |
777 ms |
85084 KB |
Output is correct |
65 |
Correct |
1036 ms |
91688 KB |
Output is correct |
66 |
Correct |
1068 ms |
91612 KB |
Output is correct |
67 |
Correct |
1059 ms |
91616 KB |
Output is correct |
68 |
Correct |
1087 ms |
93856 KB |
Output is correct |
69 |
Correct |
1084 ms |
93724 KB |
Output is correct |
70 |
Correct |
1093 ms |
93324 KB |
Output is correct |
71 |
Correct |
1085 ms |
93044 KB |
Output is correct |
72 |
Correct |
1083 ms |
93324 KB |
Output is correct |
73 |
Correct |
730 ms |
81496 KB |
Output is correct |
74 |
Correct |
748 ms |
82336 KB |
Output is correct |
75 |
Correct |
752 ms |
81492 KB |
Output is correct |
76 |
Correct |
752 ms |
81112 KB |
Output is correct |
77 |
Correct |
731 ms |
81536 KB |
Output is correct |
78 |
Correct |
933 ms |
85076 KB |
Output is correct |
79 |
Correct |
671 ms |
73544 KB |
Output is correct |
80 |
Correct |
982 ms |
84448 KB |
Output is correct |