#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
const int N = 1e6 + 6;
int ans[N];
int seg[N * 2];
void upd(int nd, int l, int r, int p, int v) {
if (l == r) {
seg[nd] = max(seg[nd], v);
return;
}
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
if (p <= mid) {
upd(nd + 1, l, mid, p, v);
} else {
upd(rs, mid + 1, r, p, v);
}
seg[nd] = max(seg[nd + 1], seg[rs]);
}
int qry(int nd, int l, int r, int s, int e) {
if (l >= s && r <= e) {
return seg[nd];
}
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
if (mid >= e) {
return qry(nd + 1, l, mid, s, e);
} else {
if (mid < s) {
return qry(rs, mid + 1, r, s, e);
} else {
return max(qry(nd + 1, l, mid, s, e), qry(rs, mid + 1, r, s, e));
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
stack<int> stk;
vector<array<int, 4>> ranges;
for (int i = 0; i < q; ++i) {
int l, r, v;
cin >> l >> r >> v;
--l, --r;
ranges.push_back({l, -r, v, i});//biggest l, then smallest r, then biggest sum
}
for (int i = n - 1; i >= 0; --i) {
while (!stk.empty() && a[stk.top()] < a[i]) {
ranges.push_back({i, -stk.top(), a[i] + a[stk.top()], -1});
stk.pop();
}
stk.push(i);
}
sort(ranges.begin(), ranges.end());
reverse(ranges.begin(), ranges.end());
for (auto [l, r, v, i] : ranges) {
r = -r;
if (i == -1) {
upd(0, 0, n - 1, r, v);
} else {
int mx = qry(0, 0, n - 1, l, r);
ans[i] = (mx <= v);
}
}
for (int i = 0; i < q; ++i) {
cout << ans[i] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2440 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2440 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
2 ms |
2648 KB |
Output is correct |
12 |
Correct |
3 ms |
2652 KB |
Output is correct |
13 |
Correct |
3 ms |
2788 KB |
Output is correct |
14 |
Correct |
4 ms |
2724 KB |
Output is correct |
15 |
Correct |
4 ms |
2784 KB |
Output is correct |
16 |
Correct |
3 ms |
2652 KB |
Output is correct |
17 |
Correct |
3 ms |
2652 KB |
Output is correct |
18 |
Correct |
3 ms |
2728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
880 ms |
50836 KB |
Output is correct |
2 |
Correct |
896 ms |
49456 KB |
Output is correct |
3 |
Correct |
904 ms |
49352 KB |
Output is correct |
4 |
Correct |
887 ms |
49536 KB |
Output is correct |
5 |
Correct |
642 ms |
30312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
7364 KB |
Output is correct |
2 |
Correct |
73 ms |
6944 KB |
Output is correct |
3 |
Correct |
57 ms |
4904 KB |
Output is correct |
4 |
Correct |
54 ms |
5064 KB |
Output is correct |
5 |
Correct |
55 ms |
4892 KB |
Output is correct |
6 |
Correct |
55 ms |
5056 KB |
Output is correct |
7 |
Correct |
55 ms |
5236 KB |
Output is correct |
8 |
Correct |
61 ms |
7108 KB |
Output is correct |
9 |
Correct |
34 ms |
4208 KB |
Output is correct |
10 |
Correct |
58 ms |
6048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2440 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
2 ms |
2648 KB |
Output is correct |
12 |
Correct |
3 ms |
2652 KB |
Output is correct |
13 |
Correct |
3 ms |
2788 KB |
Output is correct |
14 |
Correct |
4 ms |
2724 KB |
Output is correct |
15 |
Correct |
4 ms |
2784 KB |
Output is correct |
16 |
Correct |
3 ms |
2652 KB |
Output is correct |
17 |
Correct |
3 ms |
2652 KB |
Output is correct |
18 |
Correct |
3 ms |
2728 KB |
Output is correct |
19 |
Correct |
172 ms |
14800 KB |
Output is correct |
20 |
Correct |
167 ms |
13632 KB |
Output is correct |
21 |
Correct |
157 ms |
15548 KB |
Output is correct |
22 |
Correct |
157 ms |
15288 KB |
Output is correct |
23 |
Correct |
162 ms |
15520 KB |
Output is correct |
24 |
Correct |
120 ms |
9668 KB |
Output is correct |
25 |
Correct |
121 ms |
9668 KB |
Output is correct |
26 |
Correct |
122 ms |
9668 KB |
Output is correct |
27 |
Correct |
137 ms |
10436 KB |
Output is correct |
28 |
Correct |
121 ms |
9668 KB |
Output is correct |
29 |
Correct |
127 ms |
9668 KB |
Output is correct |
30 |
Correct |
124 ms |
10272 KB |
Output is correct |
31 |
Correct |
126 ms |
10180 KB |
Output is correct |
32 |
Correct |
124 ms |
9832 KB |
Output is correct |
33 |
Correct |
130 ms |
9608 KB |
Output is correct |
34 |
Correct |
119 ms |
10292 KB |
Output is correct |
35 |
Correct |
120 ms |
9668 KB |
Output is correct |
36 |
Correct |
119 ms |
9488 KB |
Output is correct |
37 |
Correct |
120 ms |
9476 KB |
Output is correct |
38 |
Correct |
119 ms |
9524 KB |
Output is correct |
39 |
Correct |
123 ms |
12736 KB |
Output is correct |
40 |
Correct |
97 ms |
9988 KB |
Output is correct |
41 |
Correct |
129 ms |
12476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2440 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
2 ms |
2648 KB |
Output is correct |
12 |
Correct |
3 ms |
2652 KB |
Output is correct |
13 |
Correct |
3 ms |
2788 KB |
Output is correct |
14 |
Correct |
4 ms |
2724 KB |
Output is correct |
15 |
Correct |
4 ms |
2784 KB |
Output is correct |
16 |
Correct |
3 ms |
2652 KB |
Output is correct |
17 |
Correct |
3 ms |
2652 KB |
Output is correct |
18 |
Correct |
3 ms |
2728 KB |
Output is correct |
19 |
Correct |
880 ms |
50836 KB |
Output is correct |
20 |
Correct |
896 ms |
49456 KB |
Output is correct |
21 |
Correct |
904 ms |
49352 KB |
Output is correct |
22 |
Correct |
887 ms |
49536 KB |
Output is correct |
23 |
Correct |
642 ms |
30312 KB |
Output is correct |
24 |
Correct |
76 ms |
7364 KB |
Output is correct |
25 |
Correct |
73 ms |
6944 KB |
Output is correct |
26 |
Correct |
57 ms |
4904 KB |
Output is correct |
27 |
Correct |
54 ms |
5064 KB |
Output is correct |
28 |
Correct |
55 ms |
4892 KB |
Output is correct |
29 |
Correct |
55 ms |
5056 KB |
Output is correct |
30 |
Correct |
55 ms |
5236 KB |
Output is correct |
31 |
Correct |
61 ms |
7108 KB |
Output is correct |
32 |
Correct |
34 ms |
4208 KB |
Output is correct |
33 |
Correct |
58 ms |
6048 KB |
Output is correct |
34 |
Correct |
172 ms |
14800 KB |
Output is correct |
35 |
Correct |
167 ms |
13632 KB |
Output is correct |
36 |
Correct |
157 ms |
15548 KB |
Output is correct |
37 |
Correct |
157 ms |
15288 KB |
Output is correct |
38 |
Correct |
162 ms |
15520 KB |
Output is correct |
39 |
Correct |
120 ms |
9668 KB |
Output is correct |
40 |
Correct |
121 ms |
9668 KB |
Output is correct |
41 |
Correct |
122 ms |
9668 KB |
Output is correct |
42 |
Correct |
137 ms |
10436 KB |
Output is correct |
43 |
Correct |
121 ms |
9668 KB |
Output is correct |
44 |
Correct |
127 ms |
9668 KB |
Output is correct |
45 |
Correct |
124 ms |
10272 KB |
Output is correct |
46 |
Correct |
126 ms |
10180 KB |
Output is correct |
47 |
Correct |
124 ms |
9832 KB |
Output is correct |
48 |
Correct |
130 ms |
9608 KB |
Output is correct |
49 |
Correct |
119 ms |
10292 KB |
Output is correct |
50 |
Correct |
120 ms |
9668 KB |
Output is correct |
51 |
Correct |
119 ms |
9488 KB |
Output is correct |
52 |
Correct |
120 ms |
9476 KB |
Output is correct |
53 |
Correct |
119 ms |
9524 KB |
Output is correct |
54 |
Correct |
123 ms |
12736 KB |
Output is correct |
55 |
Correct |
97 ms |
9988 KB |
Output is correct |
56 |
Correct |
129 ms |
12476 KB |
Output is correct |
57 |
Correct |
904 ms |
49512 KB |
Output is correct |
58 |
Correct |
894 ms |
49384 KB |
Output is correct |
59 |
Correct |
904 ms |
50920 KB |
Output is correct |
60 |
Correct |
890 ms |
49348 KB |
Output is correct |
61 |
Correct |
915 ms |
49400 KB |
Output is correct |
62 |
Correct |
884 ms |
49320 KB |
Output is correct |
63 |
Correct |
621 ms |
31440 KB |
Output is correct |
64 |
Correct |
619 ms |
31664 KB |
Output is correct |
65 |
Correct |
653 ms |
30636 KB |
Output is correct |
66 |
Correct |
647 ms |
30068 KB |
Output is correct |
67 |
Correct |
651 ms |
30028 KB |
Output is correct |
68 |
Correct |
657 ms |
30384 KB |
Output is correct |
69 |
Correct |
660 ms |
29904 KB |
Output is correct |
70 |
Correct |
647 ms |
30076 KB |
Output is correct |
71 |
Correct |
649 ms |
30176 KB |
Output is correct |
72 |
Correct |
683 ms |
30644 KB |
Output is correct |
73 |
Correct |
612 ms |
29872 KB |
Output is correct |
74 |
Correct |
624 ms |
30032 KB |
Output is correct |
75 |
Correct |
608 ms |
30132 KB |
Output is correct |
76 |
Correct |
627 ms |
29864 KB |
Output is correct |
77 |
Correct |
612 ms |
30216 KB |
Output is correct |
78 |
Correct |
646 ms |
38580 KB |
Output is correct |
79 |
Correct |
498 ms |
36528 KB |
Output is correct |
80 |
Correct |
694 ms |
45396 KB |
Output is correct |