#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int Q = N;
int n, q, a[N], bit[N];
vector<int> qs[N];
bitset<N> ans;
struct t {
int l, r, k;
} query[Q];
void upd(int i, int x) {
while (i > 0) {
bit[i] = max(bit[i], x);
i -= i & -i;
}
}
int qry(int i) {
int r = 0;
while (i <= n) {
r = max(r, bit[i]);
i += i & -i;
}
return r;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> q;
a[0] = int(1e9) + 1;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 0; i < q; ++i) {
cin >> query[i].l >> query[i].r >> query[i].k;
qs[query[i].r].push_back(i);
}
vector<int> st{0};
for (int i = 1; i <= n; ++i) {
while (a[st.back()] <= a[i]) st.pop_back();
upd(st.back(), a[i] + a[st.back()]);
st.push_back(i);
for (int j : qs[i]) ans[j] = qry(query[j].l) <= query[j].k;
}
for (int i = 0; i < q; ++i) cout << ans[i] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
23764 KB |
Output is correct |
2 |
Correct |
14 ms |
23816 KB |
Output is correct |
3 |
Correct |
17 ms |
23820 KB |
Output is correct |
4 |
Correct |
14 ms |
23764 KB |
Output is correct |
5 |
Correct |
14 ms |
23828 KB |
Output is correct |
6 |
Correct |
13 ms |
23828 KB |
Output is correct |
7 |
Correct |
14 ms |
23764 KB |
Output is correct |
8 |
Correct |
15 ms |
23832 KB |
Output is correct |
9 |
Correct |
14 ms |
23824 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
23764 KB |
Output is correct |
2 |
Correct |
14 ms |
23816 KB |
Output is correct |
3 |
Correct |
17 ms |
23820 KB |
Output is correct |
4 |
Correct |
14 ms |
23764 KB |
Output is correct |
5 |
Correct |
14 ms |
23828 KB |
Output is correct |
6 |
Correct |
13 ms |
23828 KB |
Output is correct |
7 |
Correct |
14 ms |
23764 KB |
Output is correct |
8 |
Correct |
15 ms |
23832 KB |
Output is correct |
9 |
Correct |
14 ms |
23824 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
11 |
Correct |
16 ms |
23960 KB |
Output is correct |
12 |
Correct |
15 ms |
24020 KB |
Output is correct |
13 |
Correct |
16 ms |
24020 KB |
Output is correct |
14 |
Correct |
20 ms |
24104 KB |
Output is correct |
15 |
Correct |
16 ms |
24148 KB |
Output is correct |
16 |
Correct |
16 ms |
24020 KB |
Output is correct |
17 |
Correct |
16 ms |
24048 KB |
Output is correct |
18 |
Correct |
16 ms |
24116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1008 ms |
69284 KB |
Output is correct |
2 |
Correct |
921 ms |
64256 KB |
Output is correct |
3 |
Correct |
1014 ms |
64192 KB |
Output is correct |
4 |
Correct |
922 ms |
64412 KB |
Output is correct |
5 |
Correct |
892 ms |
64208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
29568 KB |
Output is correct |
2 |
Correct |
62 ms |
28784 KB |
Output is correct |
3 |
Correct |
65 ms |
28852 KB |
Output is correct |
4 |
Correct |
77 ms |
29068 KB |
Output is correct |
5 |
Correct |
66 ms |
29124 KB |
Output is correct |
6 |
Correct |
54 ms |
28024 KB |
Output is correct |
7 |
Correct |
58 ms |
27996 KB |
Output is correct |
8 |
Correct |
80 ms |
28784 KB |
Output is correct |
9 |
Correct |
49 ms |
27032 KB |
Output is correct |
10 |
Correct |
65 ms |
28744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
23764 KB |
Output is correct |
2 |
Correct |
14 ms |
23816 KB |
Output is correct |
3 |
Correct |
17 ms |
23820 KB |
Output is correct |
4 |
Correct |
14 ms |
23764 KB |
Output is correct |
5 |
Correct |
14 ms |
23828 KB |
Output is correct |
6 |
Correct |
13 ms |
23828 KB |
Output is correct |
7 |
Correct |
14 ms |
23764 KB |
Output is correct |
8 |
Correct |
15 ms |
23832 KB |
Output is correct |
9 |
Correct |
14 ms |
23824 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
11 |
Correct |
16 ms |
23960 KB |
Output is correct |
12 |
Correct |
15 ms |
24020 KB |
Output is correct |
13 |
Correct |
16 ms |
24020 KB |
Output is correct |
14 |
Correct |
20 ms |
24104 KB |
Output is correct |
15 |
Correct |
16 ms |
24148 KB |
Output is correct |
16 |
Correct |
16 ms |
24020 KB |
Output is correct |
17 |
Correct |
16 ms |
24048 KB |
Output is correct |
18 |
Correct |
16 ms |
24116 KB |
Output is correct |
19 |
Correct |
167 ms |
36236 KB |
Output is correct |
20 |
Correct |
199 ms |
36156 KB |
Output is correct |
21 |
Correct |
139 ms |
34636 KB |
Output is correct |
22 |
Correct |
143 ms |
34452 KB |
Output is correct |
23 |
Correct |
147 ms |
34500 KB |
Output is correct |
24 |
Correct |
119 ms |
33476 KB |
Output is correct |
25 |
Correct |
142 ms |
33564 KB |
Output is correct |
26 |
Correct |
163 ms |
34256 KB |
Output is correct |
27 |
Correct |
155 ms |
34308 KB |
Output is correct |
28 |
Correct |
144 ms |
34612 KB |
Output is correct |
29 |
Correct |
190 ms |
35608 KB |
Output is correct |
30 |
Correct |
187 ms |
35360 KB |
Output is correct |
31 |
Correct |
163 ms |
35396 KB |
Output is correct |
32 |
Correct |
178 ms |
35332 KB |
Output is correct |
33 |
Correct |
170 ms |
35360 KB |
Output is correct |
34 |
Correct |
134 ms |
33356 KB |
Output is correct |
35 |
Correct |
133 ms |
33280 KB |
Output is correct |
36 |
Correct |
121 ms |
33412 KB |
Output is correct |
37 |
Correct |
138 ms |
33328 KB |
Output is correct |
38 |
Correct |
121 ms |
33428 KB |
Output is correct |
39 |
Correct |
152 ms |
35412 KB |
Output is correct |
40 |
Correct |
140 ms |
34116 KB |
Output is correct |
41 |
Correct |
143 ms |
35200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
23764 KB |
Output is correct |
2 |
Correct |
14 ms |
23816 KB |
Output is correct |
3 |
Correct |
17 ms |
23820 KB |
Output is correct |
4 |
Correct |
14 ms |
23764 KB |
Output is correct |
5 |
Correct |
14 ms |
23828 KB |
Output is correct |
6 |
Correct |
13 ms |
23828 KB |
Output is correct |
7 |
Correct |
14 ms |
23764 KB |
Output is correct |
8 |
Correct |
15 ms |
23832 KB |
Output is correct |
9 |
Correct |
14 ms |
23824 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
11 |
Correct |
16 ms |
23960 KB |
Output is correct |
12 |
Correct |
15 ms |
24020 KB |
Output is correct |
13 |
Correct |
16 ms |
24020 KB |
Output is correct |
14 |
Correct |
20 ms |
24104 KB |
Output is correct |
15 |
Correct |
16 ms |
24148 KB |
Output is correct |
16 |
Correct |
16 ms |
24020 KB |
Output is correct |
17 |
Correct |
16 ms |
24048 KB |
Output is correct |
18 |
Correct |
16 ms |
24116 KB |
Output is correct |
19 |
Correct |
1008 ms |
69284 KB |
Output is correct |
20 |
Correct |
921 ms |
64256 KB |
Output is correct |
21 |
Correct |
1014 ms |
64192 KB |
Output is correct |
22 |
Correct |
922 ms |
64412 KB |
Output is correct |
23 |
Correct |
892 ms |
64208 KB |
Output is correct |
24 |
Correct |
67 ms |
29568 KB |
Output is correct |
25 |
Correct |
62 ms |
28784 KB |
Output is correct |
26 |
Correct |
65 ms |
28852 KB |
Output is correct |
27 |
Correct |
77 ms |
29068 KB |
Output is correct |
28 |
Correct |
66 ms |
29124 KB |
Output is correct |
29 |
Correct |
54 ms |
28024 KB |
Output is correct |
30 |
Correct |
58 ms |
27996 KB |
Output is correct |
31 |
Correct |
80 ms |
28784 KB |
Output is correct |
32 |
Correct |
49 ms |
27032 KB |
Output is correct |
33 |
Correct |
65 ms |
28744 KB |
Output is correct |
34 |
Correct |
167 ms |
36236 KB |
Output is correct |
35 |
Correct |
199 ms |
36156 KB |
Output is correct |
36 |
Correct |
139 ms |
34636 KB |
Output is correct |
37 |
Correct |
143 ms |
34452 KB |
Output is correct |
38 |
Correct |
147 ms |
34500 KB |
Output is correct |
39 |
Correct |
119 ms |
33476 KB |
Output is correct |
40 |
Correct |
142 ms |
33564 KB |
Output is correct |
41 |
Correct |
163 ms |
34256 KB |
Output is correct |
42 |
Correct |
155 ms |
34308 KB |
Output is correct |
43 |
Correct |
144 ms |
34612 KB |
Output is correct |
44 |
Correct |
190 ms |
35608 KB |
Output is correct |
45 |
Correct |
187 ms |
35360 KB |
Output is correct |
46 |
Correct |
163 ms |
35396 KB |
Output is correct |
47 |
Correct |
178 ms |
35332 KB |
Output is correct |
48 |
Correct |
170 ms |
35360 KB |
Output is correct |
49 |
Correct |
134 ms |
33356 KB |
Output is correct |
50 |
Correct |
133 ms |
33280 KB |
Output is correct |
51 |
Correct |
121 ms |
33412 KB |
Output is correct |
52 |
Correct |
138 ms |
33328 KB |
Output is correct |
53 |
Correct |
121 ms |
33428 KB |
Output is correct |
54 |
Correct |
152 ms |
35412 KB |
Output is correct |
55 |
Correct |
140 ms |
34116 KB |
Output is correct |
56 |
Correct |
143 ms |
35200 KB |
Output is correct |
57 |
Correct |
956 ms |
66548 KB |
Output is correct |
58 |
Correct |
974 ms |
66672 KB |
Output is correct |
59 |
Correct |
865 ms |
62744 KB |
Output is correct |
60 |
Correct |
889 ms |
62704 KB |
Output is correct |
61 |
Correct |
927 ms |
62540 KB |
Output is correct |
62 |
Correct |
900 ms |
62540 KB |
Output is correct |
63 |
Correct |
608 ms |
52816 KB |
Output is correct |
64 |
Correct |
584 ms |
52928 KB |
Output is correct |
65 |
Correct |
809 ms |
58208 KB |
Output is correct |
66 |
Correct |
906 ms |
58212 KB |
Output is correct |
67 |
Correct |
849 ms |
58608 KB |
Output is correct |
68 |
Correct |
902 ms |
62720 KB |
Output is correct |
69 |
Correct |
927 ms |
62768 KB |
Output is correct |
70 |
Correct |
958 ms |
62228 KB |
Output is correct |
71 |
Correct |
921 ms |
61192 KB |
Output is correct |
72 |
Correct |
931 ms |
60992 KB |
Output is correct |
73 |
Correct |
567 ms |
51024 KB |
Output is correct |
74 |
Correct |
589 ms |
51064 KB |
Output is correct |
75 |
Correct |
563 ms |
50976 KB |
Output is correct |
76 |
Correct |
560 ms |
49536 KB |
Output is correct |
77 |
Correct |
549 ms |
48648 KB |
Output is correct |
78 |
Correct |
739 ms |
58184 KB |
Output is correct |
79 |
Correct |
597 ms |
52528 KB |
Output is correct |
80 |
Correct |
715 ms |
57400 KB |
Output is correct |