#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "debug.hpp"
#define debug(x...) cerr << "[" << #x << "] = [", _print(x)
#else
#define debug(x...)
#endif
#define int long long
struct Query {
int l, w, id;
};
const int MAX = 1e6 + 5;
int n, Q, a[MAX], L[MAX], rs[MAX], tree[MAX];
vector<Query> g[MAX];
void update(int idx, int val) {
for (int i = idx; i; i -= i & -i)
tree[i] = max(tree[i], val);
}
int query(int idx) {
int rs = 0;
for (int i = idx; i <= n; i += i & -i)
rs = max(rs, tree[i]);
return rs;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef DEBUG
freopen("../_input", "r", stdin);
#endif
cin >> n >> Q;
for (int i = 1; i <= n; i++) {
cin >> a[i];
L[i] = i - 1;
int tmp = i - 1;
while (tmp && a[i] >= a[tmp])
L[i] = tmp = L[tmp];
}
int l, r, w;
for (int i = 1; i <= Q; i++) {
cin >> l >> r >> w;
g[r].push_back({l, w, i});
}
for (int i = 1; i <= n; i++) {
if (L[i])
update(L[i], a[L[i]] + a[i]);
for (auto q: g[i])
rs[q.id] = query(q.l) <= q.w;
}
for (int i = 1; i <= Q; i++)
cout << rs[i] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23740 KB |
Output is correct |
2 |
Correct |
15 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23840 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23732 KB |
Output is correct |
6 |
Correct |
13 ms |
23888 KB |
Output is correct |
7 |
Correct |
13 ms |
23892 KB |
Output is correct |
8 |
Correct |
13 ms |
23808 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
13 ms |
23880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23740 KB |
Output is correct |
2 |
Correct |
15 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23840 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23732 KB |
Output is correct |
6 |
Correct |
13 ms |
23888 KB |
Output is correct |
7 |
Correct |
13 ms |
23892 KB |
Output is correct |
8 |
Correct |
13 ms |
23808 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
13 ms |
23880 KB |
Output is correct |
11 |
Correct |
14 ms |
23952 KB |
Output is correct |
12 |
Correct |
14 ms |
24064 KB |
Output is correct |
13 |
Correct |
17 ms |
24088 KB |
Output is correct |
14 |
Correct |
16 ms |
24204 KB |
Output is correct |
15 |
Correct |
15 ms |
24228 KB |
Output is correct |
16 |
Correct |
16 ms |
24212 KB |
Output is correct |
17 |
Correct |
14 ms |
24208 KB |
Output is correct |
18 |
Correct |
14 ms |
24088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
829 ms |
89656 KB |
Output is correct |
2 |
Correct |
897 ms |
122616 KB |
Output is correct |
3 |
Correct |
847 ms |
122264 KB |
Output is correct |
4 |
Correct |
834 ms |
122420 KB |
Output is correct |
5 |
Correct |
745 ms |
114876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
30356 KB |
Output is correct |
2 |
Correct |
65 ms |
32564 KB |
Output is correct |
3 |
Correct |
61 ms |
31676 KB |
Output is correct |
4 |
Correct |
57 ms |
31552 KB |
Output is correct |
5 |
Correct |
72 ms |
31592 KB |
Output is correct |
6 |
Correct |
51 ms |
31568 KB |
Output is correct |
7 |
Correct |
52 ms |
31560 KB |
Output is correct |
8 |
Correct |
55 ms |
30956 KB |
Output is correct |
9 |
Correct |
40 ms |
28984 KB |
Output is correct |
10 |
Correct |
64 ms |
30996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23740 KB |
Output is correct |
2 |
Correct |
15 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23840 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23732 KB |
Output is correct |
6 |
Correct |
13 ms |
23888 KB |
Output is correct |
7 |
Correct |
13 ms |
23892 KB |
Output is correct |
8 |
Correct |
13 ms |
23808 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
13 ms |
23880 KB |
Output is correct |
11 |
Correct |
14 ms |
23952 KB |
Output is correct |
12 |
Correct |
14 ms |
24064 KB |
Output is correct |
13 |
Correct |
17 ms |
24088 KB |
Output is correct |
14 |
Correct |
16 ms |
24204 KB |
Output is correct |
15 |
Correct |
15 ms |
24228 KB |
Output is correct |
16 |
Correct |
16 ms |
24212 KB |
Output is correct |
17 |
Correct |
14 ms |
24208 KB |
Output is correct |
18 |
Correct |
14 ms |
24088 KB |
Output is correct |
19 |
Correct |
176 ms |
43608 KB |
Output is correct |
20 |
Correct |
150 ms |
43596 KB |
Output is correct |
21 |
Correct |
122 ms |
44004 KB |
Output is correct |
22 |
Correct |
123 ms |
43908 KB |
Output is correct |
23 |
Correct |
132 ms |
43988 KB |
Output is correct |
24 |
Correct |
119 ms |
42420 KB |
Output is correct |
25 |
Correct |
115 ms |
42476 KB |
Output is correct |
26 |
Correct |
132 ms |
42152 KB |
Output is correct |
27 |
Correct |
164 ms |
42224 KB |
Output is correct |
28 |
Correct |
129 ms |
42060 KB |
Output is correct |
29 |
Correct |
149 ms |
42000 KB |
Output is correct |
30 |
Correct |
131 ms |
42060 KB |
Output is correct |
31 |
Correct |
140 ms |
41952 KB |
Output is correct |
32 |
Correct |
160 ms |
42056 KB |
Output is correct |
33 |
Correct |
154 ms |
41968 KB |
Output is correct |
34 |
Correct |
111 ms |
41688 KB |
Output is correct |
35 |
Correct |
109 ms |
41764 KB |
Output is correct |
36 |
Correct |
124 ms |
41676 KB |
Output is correct |
37 |
Correct |
103 ms |
41580 KB |
Output is correct |
38 |
Correct |
110 ms |
41712 KB |
Output is correct |
39 |
Correct |
136 ms |
40568 KB |
Output is correct |
40 |
Correct |
119 ms |
37772 KB |
Output is correct |
41 |
Correct |
122 ms |
39544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23740 KB |
Output is correct |
2 |
Correct |
15 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23840 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23732 KB |
Output is correct |
6 |
Correct |
13 ms |
23888 KB |
Output is correct |
7 |
Correct |
13 ms |
23892 KB |
Output is correct |
8 |
Correct |
13 ms |
23808 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
13 ms |
23880 KB |
Output is correct |
11 |
Correct |
14 ms |
23952 KB |
Output is correct |
12 |
Correct |
14 ms |
24064 KB |
Output is correct |
13 |
Correct |
17 ms |
24088 KB |
Output is correct |
14 |
Correct |
16 ms |
24204 KB |
Output is correct |
15 |
Correct |
15 ms |
24228 KB |
Output is correct |
16 |
Correct |
16 ms |
24212 KB |
Output is correct |
17 |
Correct |
14 ms |
24208 KB |
Output is correct |
18 |
Correct |
14 ms |
24088 KB |
Output is correct |
19 |
Correct |
829 ms |
89656 KB |
Output is correct |
20 |
Correct |
897 ms |
122616 KB |
Output is correct |
21 |
Correct |
847 ms |
122264 KB |
Output is correct |
22 |
Correct |
834 ms |
122420 KB |
Output is correct |
23 |
Correct |
745 ms |
114876 KB |
Output is correct |
24 |
Correct |
58 ms |
30356 KB |
Output is correct |
25 |
Correct |
65 ms |
32564 KB |
Output is correct |
26 |
Correct |
61 ms |
31676 KB |
Output is correct |
27 |
Correct |
57 ms |
31552 KB |
Output is correct |
28 |
Correct |
72 ms |
31592 KB |
Output is correct |
29 |
Correct |
51 ms |
31568 KB |
Output is correct |
30 |
Correct |
52 ms |
31560 KB |
Output is correct |
31 |
Correct |
55 ms |
30956 KB |
Output is correct |
32 |
Correct |
40 ms |
28984 KB |
Output is correct |
33 |
Correct |
64 ms |
30996 KB |
Output is correct |
34 |
Correct |
176 ms |
43608 KB |
Output is correct |
35 |
Correct |
150 ms |
43596 KB |
Output is correct |
36 |
Correct |
122 ms |
44004 KB |
Output is correct |
37 |
Correct |
123 ms |
43908 KB |
Output is correct |
38 |
Correct |
132 ms |
43988 KB |
Output is correct |
39 |
Correct |
119 ms |
42420 KB |
Output is correct |
40 |
Correct |
115 ms |
42476 KB |
Output is correct |
41 |
Correct |
132 ms |
42152 KB |
Output is correct |
42 |
Correct |
164 ms |
42224 KB |
Output is correct |
43 |
Correct |
129 ms |
42060 KB |
Output is correct |
44 |
Correct |
149 ms |
42000 KB |
Output is correct |
45 |
Correct |
131 ms |
42060 KB |
Output is correct |
46 |
Correct |
140 ms |
41952 KB |
Output is correct |
47 |
Correct |
160 ms |
42056 KB |
Output is correct |
48 |
Correct |
154 ms |
41968 KB |
Output is correct |
49 |
Correct |
111 ms |
41688 KB |
Output is correct |
50 |
Correct |
109 ms |
41764 KB |
Output is correct |
51 |
Correct |
124 ms |
41676 KB |
Output is correct |
52 |
Correct |
103 ms |
41580 KB |
Output is correct |
53 |
Correct |
110 ms |
41712 KB |
Output is correct |
54 |
Correct |
136 ms |
40568 KB |
Output is correct |
55 |
Correct |
119 ms |
37772 KB |
Output is correct |
56 |
Correct |
122 ms |
39544 KB |
Output is correct |
57 |
Correct |
855 ms |
123392 KB |
Output is correct |
58 |
Correct |
840 ms |
123284 KB |
Output is correct |
59 |
Correct |
794 ms |
124076 KB |
Output is correct |
60 |
Correct |
832 ms |
124136 KB |
Output is correct |
61 |
Correct |
790 ms |
123976 KB |
Output is correct |
62 |
Correct |
814 ms |
124096 KB |
Output is correct |
63 |
Correct |
573 ms |
116412 KB |
Output is correct |
64 |
Correct |
565 ms |
116400 KB |
Output is correct |
65 |
Correct |
815 ms |
116344 KB |
Output is correct |
66 |
Correct |
741 ms |
116300 KB |
Output is correct |
67 |
Correct |
763 ms |
116380 KB |
Output is correct |
68 |
Correct |
771 ms |
115560 KB |
Output is correct |
69 |
Correct |
766 ms |
115572 KB |
Output is correct |
70 |
Correct |
773 ms |
115860 KB |
Output is correct |
71 |
Correct |
783 ms |
115608 KB |
Output is correct |
72 |
Correct |
768 ms |
115568 KB |
Output is correct |
73 |
Correct |
477 ms |
110564 KB |
Output is correct |
74 |
Correct |
539 ms |
111296 KB |
Output is correct |
75 |
Correct |
503 ms |
110160 KB |
Output is correct |
76 |
Correct |
513 ms |
110692 KB |
Output is correct |
77 |
Correct |
489 ms |
110356 KB |
Output is correct |
78 |
Correct |
699 ms |
109716 KB |
Output is correct |
79 |
Correct |
536 ms |
92172 KB |
Output is correct |
80 |
Correct |
704 ms |
103156 KB |
Output is correct |