#include<bits/stdc++.h>
using namespace std;
const int maxn = 1<<20;
int n, m, a[maxn], f[maxn], ans[maxn];
vector<array<int, 3>> q[maxn];
void upd(int i, int x) {
for(;i; i -= i&-i) f[i] = max(f[i], x);
}
int get(int i) {
int r = 0;
for(;i <= n; i += i&-i) r = max(f[i], r);
return r;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
a[0] = 1<<30;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int l, r, k, i = 0; i < m; i++) {
cin >> l >> r >> k;
q[r].push_back({l, k, i});
}
vector<int> t {0};
for(int i = 1; i <= n; i++) {
while(a[t.back()] <= a[i]) t.pop_back();
if(t.back()) upd(t.back(), a[t.back()] + a[i]);
t.push_back(i);
for(auto [l, k, p] : q[i]) ans[p] = get(l) <= k;
}
for(int i = 0; i < m; i++) cout << ans[i] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
24916 KB |
Output is correct |
2 |
Correct |
13 ms |
24916 KB |
Output is correct |
3 |
Correct |
13 ms |
24916 KB |
Output is correct |
4 |
Correct |
13 ms |
24948 KB |
Output is correct |
5 |
Correct |
13 ms |
24880 KB |
Output is correct |
6 |
Correct |
14 ms |
24904 KB |
Output is correct |
7 |
Correct |
13 ms |
24928 KB |
Output is correct |
8 |
Correct |
13 ms |
24916 KB |
Output is correct |
9 |
Correct |
14 ms |
24916 KB |
Output is correct |
10 |
Correct |
14 ms |
24876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
24916 KB |
Output is correct |
2 |
Correct |
13 ms |
24916 KB |
Output is correct |
3 |
Correct |
13 ms |
24916 KB |
Output is correct |
4 |
Correct |
13 ms |
24948 KB |
Output is correct |
5 |
Correct |
13 ms |
24880 KB |
Output is correct |
6 |
Correct |
14 ms |
24904 KB |
Output is correct |
7 |
Correct |
13 ms |
24928 KB |
Output is correct |
8 |
Correct |
13 ms |
24916 KB |
Output is correct |
9 |
Correct |
14 ms |
24916 KB |
Output is correct |
10 |
Correct |
14 ms |
24876 KB |
Output is correct |
11 |
Correct |
13 ms |
25052 KB |
Output is correct |
12 |
Correct |
15 ms |
25044 KB |
Output is correct |
13 |
Correct |
16 ms |
25016 KB |
Output is correct |
14 |
Correct |
17 ms |
25044 KB |
Output is correct |
15 |
Correct |
16 ms |
25044 KB |
Output is correct |
16 |
Correct |
15 ms |
25044 KB |
Output is correct |
17 |
Correct |
16 ms |
25124 KB |
Output is correct |
18 |
Correct |
15 ms |
25044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
790 ms |
60448 KB |
Output is correct |
2 |
Correct |
815 ms |
60340 KB |
Output is correct |
3 |
Correct |
808 ms |
60396 KB |
Output is correct |
4 |
Correct |
789 ms |
60312 KB |
Output is correct |
5 |
Correct |
752 ms |
56492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
28452 KB |
Output is correct |
2 |
Correct |
64 ms |
28620 KB |
Output is correct |
3 |
Correct |
61 ms |
29004 KB |
Output is correct |
4 |
Correct |
62 ms |
29932 KB |
Output is correct |
5 |
Correct |
64 ms |
30052 KB |
Output is correct |
6 |
Correct |
54 ms |
29472 KB |
Output is correct |
7 |
Correct |
55 ms |
29416 KB |
Output is correct |
8 |
Correct |
62 ms |
29576 KB |
Output is correct |
9 |
Correct |
44 ms |
28256 KB |
Output is correct |
10 |
Correct |
61 ms |
29496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
24916 KB |
Output is correct |
2 |
Correct |
13 ms |
24916 KB |
Output is correct |
3 |
Correct |
13 ms |
24916 KB |
Output is correct |
4 |
Correct |
13 ms |
24948 KB |
Output is correct |
5 |
Correct |
13 ms |
24880 KB |
Output is correct |
6 |
Correct |
14 ms |
24904 KB |
Output is correct |
7 |
Correct |
13 ms |
24928 KB |
Output is correct |
8 |
Correct |
13 ms |
24916 KB |
Output is correct |
9 |
Correct |
14 ms |
24916 KB |
Output is correct |
10 |
Correct |
14 ms |
24876 KB |
Output is correct |
11 |
Correct |
13 ms |
25052 KB |
Output is correct |
12 |
Correct |
15 ms |
25044 KB |
Output is correct |
13 |
Correct |
16 ms |
25016 KB |
Output is correct |
14 |
Correct |
17 ms |
25044 KB |
Output is correct |
15 |
Correct |
16 ms |
25044 KB |
Output is correct |
16 |
Correct |
15 ms |
25044 KB |
Output is correct |
17 |
Correct |
16 ms |
25124 KB |
Output is correct |
18 |
Correct |
15 ms |
25044 KB |
Output is correct |
19 |
Correct |
147 ms |
31904 KB |
Output is correct |
20 |
Correct |
140 ms |
32436 KB |
Output is correct |
21 |
Correct |
129 ms |
34636 KB |
Output is correct |
22 |
Correct |
129 ms |
37768 KB |
Output is correct |
23 |
Correct |
126 ms |
37824 KB |
Output is correct |
24 |
Correct |
116 ms |
36844 KB |
Output is correct |
25 |
Correct |
116 ms |
36936 KB |
Output is correct |
26 |
Correct |
143 ms |
37308 KB |
Output is correct |
27 |
Correct |
133 ms |
37196 KB |
Output is correct |
28 |
Correct |
140 ms |
37444 KB |
Output is correct |
29 |
Correct |
156 ms |
37724 KB |
Output is correct |
30 |
Correct |
154 ms |
37720 KB |
Output is correct |
31 |
Correct |
143 ms |
37732 KB |
Output is correct |
32 |
Correct |
145 ms |
37632 KB |
Output is correct |
33 |
Correct |
143 ms |
37684 KB |
Output is correct |
34 |
Correct |
114 ms |
36616 KB |
Output is correct |
35 |
Correct |
108 ms |
36448 KB |
Output is correct |
36 |
Correct |
108 ms |
36392 KB |
Output is correct |
37 |
Correct |
112 ms |
36300 KB |
Output is correct |
38 |
Correct |
110 ms |
36500 KB |
Output is correct |
39 |
Correct |
134 ms |
36148 KB |
Output is correct |
40 |
Correct |
111 ms |
34676 KB |
Output is correct |
41 |
Correct |
129 ms |
35496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
24916 KB |
Output is correct |
2 |
Correct |
13 ms |
24916 KB |
Output is correct |
3 |
Correct |
13 ms |
24916 KB |
Output is correct |
4 |
Correct |
13 ms |
24948 KB |
Output is correct |
5 |
Correct |
13 ms |
24880 KB |
Output is correct |
6 |
Correct |
14 ms |
24904 KB |
Output is correct |
7 |
Correct |
13 ms |
24928 KB |
Output is correct |
8 |
Correct |
13 ms |
24916 KB |
Output is correct |
9 |
Correct |
14 ms |
24916 KB |
Output is correct |
10 |
Correct |
14 ms |
24876 KB |
Output is correct |
11 |
Correct |
13 ms |
25052 KB |
Output is correct |
12 |
Correct |
15 ms |
25044 KB |
Output is correct |
13 |
Correct |
16 ms |
25016 KB |
Output is correct |
14 |
Correct |
17 ms |
25044 KB |
Output is correct |
15 |
Correct |
16 ms |
25044 KB |
Output is correct |
16 |
Correct |
15 ms |
25044 KB |
Output is correct |
17 |
Correct |
16 ms |
25124 KB |
Output is correct |
18 |
Correct |
15 ms |
25044 KB |
Output is correct |
19 |
Correct |
790 ms |
60448 KB |
Output is correct |
20 |
Correct |
815 ms |
60340 KB |
Output is correct |
21 |
Correct |
808 ms |
60396 KB |
Output is correct |
22 |
Correct |
789 ms |
60312 KB |
Output is correct |
23 |
Correct |
752 ms |
56492 KB |
Output is correct |
24 |
Correct |
63 ms |
28452 KB |
Output is correct |
25 |
Correct |
64 ms |
28620 KB |
Output is correct |
26 |
Correct |
61 ms |
29004 KB |
Output is correct |
27 |
Correct |
62 ms |
29932 KB |
Output is correct |
28 |
Correct |
64 ms |
30052 KB |
Output is correct |
29 |
Correct |
54 ms |
29472 KB |
Output is correct |
30 |
Correct |
55 ms |
29416 KB |
Output is correct |
31 |
Correct |
62 ms |
29576 KB |
Output is correct |
32 |
Correct |
44 ms |
28256 KB |
Output is correct |
33 |
Correct |
61 ms |
29496 KB |
Output is correct |
34 |
Correct |
147 ms |
31904 KB |
Output is correct |
35 |
Correct |
140 ms |
32436 KB |
Output is correct |
36 |
Correct |
129 ms |
34636 KB |
Output is correct |
37 |
Correct |
129 ms |
37768 KB |
Output is correct |
38 |
Correct |
126 ms |
37824 KB |
Output is correct |
39 |
Correct |
116 ms |
36844 KB |
Output is correct |
40 |
Correct |
116 ms |
36936 KB |
Output is correct |
41 |
Correct |
143 ms |
37308 KB |
Output is correct |
42 |
Correct |
133 ms |
37196 KB |
Output is correct |
43 |
Correct |
140 ms |
37444 KB |
Output is correct |
44 |
Correct |
156 ms |
37724 KB |
Output is correct |
45 |
Correct |
154 ms |
37720 KB |
Output is correct |
46 |
Correct |
143 ms |
37732 KB |
Output is correct |
47 |
Correct |
145 ms |
37632 KB |
Output is correct |
48 |
Correct |
143 ms |
37684 KB |
Output is correct |
49 |
Correct |
114 ms |
36616 KB |
Output is correct |
50 |
Correct |
108 ms |
36448 KB |
Output is correct |
51 |
Correct |
108 ms |
36392 KB |
Output is correct |
52 |
Correct |
112 ms |
36300 KB |
Output is correct |
53 |
Correct |
110 ms |
36500 KB |
Output is correct |
54 |
Correct |
134 ms |
36148 KB |
Output is correct |
55 |
Correct |
111 ms |
34676 KB |
Output is correct |
56 |
Correct |
129 ms |
35496 KB |
Output is correct |
57 |
Correct |
857 ms |
93556 KB |
Output is correct |
58 |
Correct |
859 ms |
93428 KB |
Output is correct |
59 |
Correct |
843 ms |
92028 KB |
Output is correct |
60 |
Correct |
945 ms |
91876 KB |
Output is correct |
61 |
Correct |
860 ms |
91996 KB |
Output is correct |
62 |
Correct |
798 ms |
92044 KB |
Output is correct |
63 |
Correct |
568 ms |
84800 KB |
Output is correct |
64 |
Correct |
545 ms |
84828 KB |
Output is correct |
65 |
Correct |
734 ms |
87744 KB |
Output is correct |
66 |
Correct |
714 ms |
87852 KB |
Output is correct |
67 |
Correct |
755 ms |
88020 KB |
Output is correct |
68 |
Correct |
785 ms |
89520 KB |
Output is correct |
69 |
Correct |
817 ms |
89468 KB |
Output is correct |
70 |
Correct |
808 ms |
87368 KB |
Output is correct |
71 |
Correct |
818 ms |
89296 KB |
Output is correct |
72 |
Correct |
816 ms |
89200 KB |
Output is correct |
73 |
Correct |
497 ms |
80588 KB |
Output is correct |
74 |
Correct |
520 ms |
81556 KB |
Output is correct |
75 |
Correct |
600 ms |
80456 KB |
Output is correct |
76 |
Correct |
548 ms |
80252 KB |
Output is correct |
77 |
Correct |
537 ms |
80024 KB |
Output is correct |
78 |
Correct |
768 ms |
82936 KB |
Output is correct |
79 |
Correct |
613 ms |
72652 KB |
Output is correct |
80 |
Correct |
765 ms |
78796 KB |
Output is correct |