#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) cin >> a[i];
vector<int> st;
vector<vector<int>> v(n + 1);
for (int i = 1; i <= n; i++) {
while (!st.empty() && a[i] >= a[st.back()]) {
st.pop_back();
}
if (!st.empty()) {
v[st.back()].push_back(i);
}
st.push_back(i);
}
vector<vector<array<int, 3>>> qr(n + 1);
for (int i = 0; i < m; i++) {
int l, r, x;
cin >> l >> r >> x;
qr[l].push_back({r, x, i});
}
vector<int> fen(n + 1);
auto upd = [&](int x, int val) {
for (; x <= n; x += x & -x) fen[x] = max(fen[x], val);
};
auto qry = [&](int x) {
int res = 0;
for (; x > 0; x -= x & -x) res = max(res, fen[x]);
return res;
};
vector<int> ans(m);
for (int l = n; l >= 1; l--) {
for (auto j : v[l]) {
upd(j, a[l] + a[j]);
}
for (auto [r, x, i] : qr[l]) {
ans[i] = (qry(r) <= x ? 1 : 0);
}
}
for (int i = 0; i < m; i++) cout << ans[i] << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
480 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
480 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
860 KB |
Output is correct |
13 |
Correct |
2 ms |
1056 KB |
Output is correct |
14 |
Correct |
2 ms |
1076 KB |
Output is correct |
15 |
Correct |
2 ms |
1116 KB |
Output is correct |
16 |
Correct |
2 ms |
980 KB |
Output is correct |
17 |
Correct |
2 ms |
860 KB |
Output is correct |
18 |
Correct |
2 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
683 ms |
155856 KB |
Output is correct |
2 |
Correct |
657 ms |
157008 KB |
Output is correct |
3 |
Correct |
663 ms |
156760 KB |
Output is correct |
4 |
Correct |
669 ms |
156932 KB |
Output is correct |
5 |
Correct |
625 ms |
138108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
14676 KB |
Output is correct |
2 |
Correct |
41 ms |
15064 KB |
Output is correct |
3 |
Correct |
34 ms |
12888 KB |
Output is correct |
4 |
Correct |
34 ms |
12748 KB |
Output is correct |
5 |
Correct |
35 ms |
12880 KB |
Output is correct |
6 |
Correct |
28 ms |
12988 KB |
Output is correct |
7 |
Correct |
31 ms |
12996 KB |
Output is correct |
8 |
Correct |
34 ms |
12876 KB |
Output is correct |
9 |
Correct |
22 ms |
5644 KB |
Output is correct |
10 |
Correct |
35 ms |
12636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
480 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
860 KB |
Output is correct |
13 |
Correct |
2 ms |
1056 KB |
Output is correct |
14 |
Correct |
2 ms |
1076 KB |
Output is correct |
15 |
Correct |
2 ms |
1116 KB |
Output is correct |
16 |
Correct |
2 ms |
980 KB |
Output is correct |
17 |
Correct |
2 ms |
860 KB |
Output is correct |
18 |
Correct |
2 ms |
860 KB |
Output is correct |
19 |
Correct |
111 ms |
31568 KB |
Output is correct |
20 |
Correct |
103 ms |
31568 KB |
Output is correct |
21 |
Correct |
93 ms |
32488 KB |
Output is correct |
22 |
Correct |
98 ms |
32600 KB |
Output is correct |
23 |
Correct |
93 ms |
32468 KB |
Output is correct |
24 |
Correct |
70 ms |
28892 KB |
Output is correct |
25 |
Correct |
79 ms |
28756 KB |
Output is correct |
26 |
Correct |
90 ms |
28496 KB |
Output is correct |
27 |
Correct |
92 ms |
28496 KB |
Output is correct |
28 |
Correct |
82 ms |
28244 KB |
Output is correct |
29 |
Correct |
86 ms |
27732 KB |
Output is correct |
30 |
Correct |
81 ms |
27856 KB |
Output is correct |
31 |
Correct |
82 ms |
27984 KB |
Output is correct |
32 |
Correct |
88 ms |
27904 KB |
Output is correct |
33 |
Correct |
94 ms |
27864 KB |
Output is correct |
34 |
Correct |
71 ms |
27772 KB |
Output is correct |
35 |
Correct |
62 ms |
27728 KB |
Output is correct |
36 |
Correct |
95 ms |
27472 KB |
Output is correct |
37 |
Correct |
68 ms |
27480 KB |
Output is correct |
38 |
Correct |
70 ms |
27632 KB |
Output is correct |
39 |
Correct |
85 ms |
27396 KB |
Output is correct |
40 |
Correct |
61 ms |
20864 KB |
Output is correct |
41 |
Correct |
92 ms |
26364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
480 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
860 KB |
Output is correct |
13 |
Correct |
2 ms |
1056 KB |
Output is correct |
14 |
Correct |
2 ms |
1076 KB |
Output is correct |
15 |
Correct |
2 ms |
1116 KB |
Output is correct |
16 |
Correct |
2 ms |
980 KB |
Output is correct |
17 |
Correct |
2 ms |
860 KB |
Output is correct |
18 |
Correct |
2 ms |
860 KB |
Output is correct |
19 |
Correct |
683 ms |
155856 KB |
Output is correct |
20 |
Correct |
657 ms |
157008 KB |
Output is correct |
21 |
Correct |
663 ms |
156760 KB |
Output is correct |
22 |
Correct |
669 ms |
156932 KB |
Output is correct |
23 |
Correct |
625 ms |
138108 KB |
Output is correct |
24 |
Correct |
44 ms |
14676 KB |
Output is correct |
25 |
Correct |
41 ms |
15064 KB |
Output is correct |
26 |
Correct |
34 ms |
12888 KB |
Output is correct |
27 |
Correct |
34 ms |
12748 KB |
Output is correct |
28 |
Correct |
35 ms |
12880 KB |
Output is correct |
29 |
Correct |
28 ms |
12988 KB |
Output is correct |
30 |
Correct |
31 ms |
12996 KB |
Output is correct |
31 |
Correct |
34 ms |
12876 KB |
Output is correct |
32 |
Correct |
22 ms |
5644 KB |
Output is correct |
33 |
Correct |
35 ms |
12636 KB |
Output is correct |
34 |
Correct |
111 ms |
31568 KB |
Output is correct |
35 |
Correct |
103 ms |
31568 KB |
Output is correct |
36 |
Correct |
93 ms |
32488 KB |
Output is correct |
37 |
Correct |
98 ms |
32600 KB |
Output is correct |
38 |
Correct |
93 ms |
32468 KB |
Output is correct |
39 |
Correct |
70 ms |
28892 KB |
Output is correct |
40 |
Correct |
79 ms |
28756 KB |
Output is correct |
41 |
Correct |
90 ms |
28496 KB |
Output is correct |
42 |
Correct |
92 ms |
28496 KB |
Output is correct |
43 |
Correct |
82 ms |
28244 KB |
Output is correct |
44 |
Correct |
86 ms |
27732 KB |
Output is correct |
45 |
Correct |
81 ms |
27856 KB |
Output is correct |
46 |
Correct |
82 ms |
27984 KB |
Output is correct |
47 |
Correct |
88 ms |
27904 KB |
Output is correct |
48 |
Correct |
94 ms |
27864 KB |
Output is correct |
49 |
Correct |
71 ms |
27772 KB |
Output is correct |
50 |
Correct |
62 ms |
27728 KB |
Output is correct |
51 |
Correct |
95 ms |
27472 KB |
Output is correct |
52 |
Correct |
68 ms |
27480 KB |
Output is correct |
53 |
Correct |
70 ms |
27632 KB |
Output is correct |
54 |
Correct |
85 ms |
27396 KB |
Output is correct |
55 |
Correct |
61 ms |
20864 KB |
Output is correct |
56 |
Correct |
92 ms |
26364 KB |
Output is correct |
57 |
Correct |
762 ms |
157260 KB |
Output is correct |
58 |
Correct |
791 ms |
157260 KB |
Output is correct |
59 |
Correct |
764 ms |
159056 KB |
Output is correct |
60 |
Correct |
804 ms |
159056 KB |
Output is correct |
61 |
Correct |
768 ms |
158800 KB |
Output is correct |
62 |
Correct |
777 ms |
158932 KB |
Output is correct |
63 |
Correct |
398 ms |
137720 KB |
Output is correct |
64 |
Correct |
362 ms |
137424 KB |
Output is correct |
65 |
Correct |
682 ms |
140628 KB |
Output is correct |
66 |
Correct |
654 ms |
140636 KB |
Output is correct |
67 |
Correct |
630 ms |
140280 KB |
Output is correct |
68 |
Correct |
713 ms |
138320 KB |
Output is correct |
69 |
Correct |
730 ms |
138536 KB |
Output is correct |
70 |
Correct |
688 ms |
138736 KB |
Output is correct |
71 |
Correct |
766 ms |
138704 KB |
Output is correct |
72 |
Correct |
695 ms |
138840 KB |
Output is correct |
73 |
Correct |
352 ms |
133856 KB |
Output is correct |
74 |
Correct |
414 ms |
134604 KB |
Output is correct |
75 |
Correct |
382 ms |
133600 KB |
Output is correct |
76 |
Correct |
391 ms |
134116 KB |
Output is correct |
77 |
Correct |
368 ms |
133976 KB |
Output is correct |
78 |
Correct |
575 ms |
137076 KB |
Output is correct |
79 |
Correct |
447 ms |
94672 KB |
Output is correct |
80 |
Correct |
568 ms |
132656 KB |
Output is correct |