#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int tree[4*maxn], n, q;
void U(int u, int tl, int tr, int p, int v) {
if(tl == tr) {
tree[u] = max(tree[u], v);
} else {
int tm = (tl + tr) / 2;
if(p <= tm) U(2*u, tl, tm, p, v);
else U(2*u+1, tm+1, tr, p, v);
tree[u] = max(tree[2*u], tree[2*u+1]);
}
}
int Q(int u, int tl, int tr, int l, int r) {
if(l > tr || tl > r) return 0;
if(l <= tl && tr <= r) return tree[u];
int tm = (tl + tr) / 2;
return max(Q(2*u, tl, tm, l, r), Q(2*u+1, tm+1, tr, l, r));
}
int main() {
cin >> n >> q;
vector<int> v(n+1), ans(q);
for(int i=1; i<=n; i++) cin >> v[i];
vector<array<int, 3> > qus[n+1];
for(int i=0; i<q; i++) {
int l, r, k; cin >> l >> r >> k;
qus[r].push_back({ l, k, i });
}
stack<int> st;
for(int i=1; i<=n; i++) {
while(!st.empty() && v[st.top()] <= v[i]) st.pop();
if(!st.empty()) U(1, 1, n, st.top(), v[st.top()] + v[i]);
for(auto &[l, k, id] : qus[i]) ans[id] = (Q(1, 1, n, l, i) <= k);
st.push(i);
}
for(int x : ans) cout << x << '\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 |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 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 |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 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 |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
604 KB |
Output is correct |
13 |
Correct |
4 ms |
728 KB |
Output is correct |
14 |
Correct |
6 ms |
604 KB |
Output is correct |
15 |
Correct |
6 ms |
604 KB |
Output is correct |
16 |
Correct |
5 ms |
604 KB |
Output is correct |
17 |
Correct |
4 ms |
604 KB |
Output is correct |
18 |
Correct |
4 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1438 ms |
63556 KB |
Output is correct |
2 |
Correct |
1476 ms |
63572 KB |
Output is correct |
3 |
Correct |
1500 ms |
63648 KB |
Output is correct |
4 |
Correct |
1474 ms |
63552 KB |
Output is correct |
5 |
Correct |
1361 ms |
55392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
122 ms |
6736 KB |
Output is correct |
2 |
Correct |
95 ms |
6480 KB |
Output is correct |
3 |
Correct |
92 ms |
5716 KB |
Output is correct |
4 |
Correct |
97 ms |
5812 KB |
Output is correct |
5 |
Correct |
89 ms |
5716 KB |
Output is correct |
6 |
Correct |
81 ms |
5456 KB |
Output is correct |
7 |
Correct |
78 ms |
5460 KB |
Output is correct |
8 |
Correct |
78 ms |
5836 KB |
Output is correct |
9 |
Correct |
49 ms |
2312 KB |
Output is correct |
10 |
Correct |
77 ms |
5736 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 |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 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 |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
604 KB |
Output is correct |
13 |
Correct |
4 ms |
728 KB |
Output is correct |
14 |
Correct |
6 ms |
604 KB |
Output is correct |
15 |
Correct |
6 ms |
604 KB |
Output is correct |
16 |
Correct |
5 ms |
604 KB |
Output is correct |
17 |
Correct |
4 ms |
604 KB |
Output is correct |
18 |
Correct |
4 ms |
600 KB |
Output is correct |
19 |
Correct |
255 ms |
13396 KB |
Output is correct |
20 |
Correct |
261 ms |
13208 KB |
Output is correct |
21 |
Correct |
241 ms |
12884 KB |
Output is correct |
22 |
Correct |
262 ms |
12880 KB |
Output is correct |
23 |
Correct |
240 ms |
12764 KB |
Output is correct |
24 |
Correct |
247 ms |
10836 KB |
Output is correct |
25 |
Correct |
243 ms |
10656 KB |
Output is correct |
26 |
Correct |
281 ms |
10972 KB |
Output is correct |
27 |
Correct |
239 ms |
10820 KB |
Output is correct |
28 |
Correct |
258 ms |
10956 KB |
Output is correct |
29 |
Correct |
269 ms |
11196 KB |
Output is correct |
30 |
Correct |
282 ms |
11200 KB |
Output is correct |
31 |
Correct |
273 ms |
11200 KB |
Output is correct |
32 |
Correct |
305 ms |
11228 KB |
Output is correct |
33 |
Correct |
257 ms |
11160 KB |
Output is correct |
34 |
Correct |
214 ms |
10460 KB |
Output is correct |
35 |
Correct |
246 ms |
10464 KB |
Output is correct |
36 |
Correct |
223 ms |
10460 KB |
Output is correct |
37 |
Correct |
245 ms |
10448 KB |
Output is correct |
38 |
Correct |
225 ms |
10448 KB |
Output is correct |
39 |
Correct |
220 ms |
11528 KB |
Output is correct |
40 |
Correct |
175 ms |
8712 KB |
Output is correct |
41 |
Correct |
212 ms |
11140 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 |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 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 |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
604 KB |
Output is correct |
13 |
Correct |
4 ms |
728 KB |
Output is correct |
14 |
Correct |
6 ms |
604 KB |
Output is correct |
15 |
Correct |
6 ms |
604 KB |
Output is correct |
16 |
Correct |
5 ms |
604 KB |
Output is correct |
17 |
Correct |
4 ms |
604 KB |
Output is correct |
18 |
Correct |
4 ms |
600 KB |
Output is correct |
19 |
Correct |
1438 ms |
63556 KB |
Output is correct |
20 |
Correct |
1476 ms |
63572 KB |
Output is correct |
21 |
Correct |
1500 ms |
63648 KB |
Output is correct |
22 |
Correct |
1474 ms |
63552 KB |
Output is correct |
23 |
Correct |
1361 ms |
55392 KB |
Output is correct |
24 |
Correct |
122 ms |
6736 KB |
Output is correct |
25 |
Correct |
95 ms |
6480 KB |
Output is correct |
26 |
Correct |
92 ms |
5716 KB |
Output is correct |
27 |
Correct |
97 ms |
5812 KB |
Output is correct |
28 |
Correct |
89 ms |
5716 KB |
Output is correct |
29 |
Correct |
81 ms |
5456 KB |
Output is correct |
30 |
Correct |
78 ms |
5460 KB |
Output is correct |
31 |
Correct |
78 ms |
5836 KB |
Output is correct |
32 |
Correct |
49 ms |
2312 KB |
Output is correct |
33 |
Correct |
77 ms |
5736 KB |
Output is correct |
34 |
Correct |
255 ms |
13396 KB |
Output is correct |
35 |
Correct |
261 ms |
13208 KB |
Output is correct |
36 |
Correct |
241 ms |
12884 KB |
Output is correct |
37 |
Correct |
262 ms |
12880 KB |
Output is correct |
38 |
Correct |
240 ms |
12764 KB |
Output is correct |
39 |
Correct |
247 ms |
10836 KB |
Output is correct |
40 |
Correct |
243 ms |
10656 KB |
Output is correct |
41 |
Correct |
281 ms |
10972 KB |
Output is correct |
42 |
Correct |
239 ms |
10820 KB |
Output is correct |
43 |
Correct |
258 ms |
10956 KB |
Output is correct |
44 |
Correct |
269 ms |
11196 KB |
Output is correct |
45 |
Correct |
282 ms |
11200 KB |
Output is correct |
46 |
Correct |
273 ms |
11200 KB |
Output is correct |
47 |
Correct |
305 ms |
11228 KB |
Output is correct |
48 |
Correct |
257 ms |
11160 KB |
Output is correct |
49 |
Correct |
214 ms |
10460 KB |
Output is correct |
50 |
Correct |
246 ms |
10464 KB |
Output is correct |
51 |
Correct |
223 ms |
10460 KB |
Output is correct |
52 |
Correct |
245 ms |
10448 KB |
Output is correct |
53 |
Correct |
225 ms |
10448 KB |
Output is correct |
54 |
Correct |
220 ms |
11528 KB |
Output is correct |
55 |
Correct |
175 ms |
8712 KB |
Output is correct |
56 |
Correct |
212 ms |
11140 KB |
Output is correct |
57 |
Correct |
1603 ms |
62972 KB |
Output is correct |
58 |
Correct |
1560 ms |
63088 KB |
Output is correct |
59 |
Correct |
1397 ms |
61516 KB |
Output is correct |
60 |
Correct |
1360 ms |
61476 KB |
Output is correct |
61 |
Correct |
1382 ms |
61520 KB |
Output is correct |
62 |
Correct |
1436 ms |
61508 KB |
Output is correct |
63 |
Correct |
1096 ms |
52052 KB |
Output is correct |
64 |
Correct |
1091 ms |
52048 KB |
Output is correct |
65 |
Correct |
1277 ms |
53312 KB |
Output is correct |
66 |
Correct |
1373 ms |
53324 KB |
Output is correct |
67 |
Correct |
1294 ms |
53328 KB |
Output is correct |
68 |
Correct |
1354 ms |
54860 KB |
Output is correct |
69 |
Correct |
1341 ms |
54868 KB |
Output is correct |
70 |
Correct |
1409 ms |
54612 KB |
Output is correct |
71 |
Correct |
1377 ms |
54596 KB |
Output is correct |
72 |
Correct |
1350 ms |
54608 KB |
Output is correct |
73 |
Correct |
1055 ms |
51532 KB |
Output is correct |
74 |
Correct |
1064 ms |
51520 KB |
Output is correct |
75 |
Correct |
1107 ms |
51536 KB |
Output is correct |
76 |
Correct |
1051 ms |
51664 KB |
Output is correct |
77 |
Correct |
1067 ms |
51368 KB |
Output is correct |
78 |
Correct |
1205 ms |
55852 KB |
Output is correct |
79 |
Correct |
907 ms |
37776 KB |
Output is correct |
80 |
Correct |
1165 ms |
53480 KB |
Output is correct |