#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});//ranges with higher value come later
stk.pop();
}
stk.push(i);
}
sort(ranges.begin(), ranges.end());
reverse(ranges.begin(), ranges.end());
//deb(ranges) cout << '\n';
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 |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2448 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 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 |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2448 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 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 |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 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 |
2652 KB |
Output is correct |
14 |
Correct |
4 ms |
2784 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 |
2792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
888 ms |
50280 KB |
Output is correct |
2 |
Correct |
888 ms |
50024 KB |
Output is correct |
3 |
Correct |
994 ms |
82816 KB |
Output is correct |
4 |
Correct |
889 ms |
82524 KB |
Output is correct |
5 |
Correct |
662 ms |
63360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
7360 KB |
Output is correct |
2 |
Correct |
73 ms |
9264 KB |
Output is correct |
3 |
Correct |
57 ms |
6868 KB |
Output is correct |
4 |
Correct |
55 ms |
6856 KB |
Output is correct |
5 |
Correct |
55 ms |
6888 KB |
Output is correct |
6 |
Correct |
60 ms |
7124 KB |
Output is correct |
7 |
Correct |
55 ms |
7112 KB |
Output is correct |
8 |
Correct |
61 ms |
8200 KB |
Output is correct |
9 |
Correct |
35 ms |
5544 KB |
Output is correct |
10 |
Correct |
59 ms |
7760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2448 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 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 |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 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 |
2652 KB |
Output is correct |
14 |
Correct |
4 ms |
2784 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 |
2792 KB |
Output is correct |
19 |
Correct |
168 ms |
19392 KB |
Output is correct |
20 |
Correct |
173 ms |
21792 KB |
Output is correct |
21 |
Correct |
174 ms |
20916 KB |
Output is correct |
22 |
Correct |
155 ms |
20152 KB |
Output is correct |
23 |
Correct |
158 ms |
21176 KB |
Output is correct |
24 |
Correct |
123 ms |
15812 KB |
Output is correct |
25 |
Correct |
123 ms |
15900 KB |
Output is correct |
26 |
Correct |
123 ms |
16064 KB |
Output is correct |
27 |
Correct |
124 ms |
16468 KB |
Output is correct |
28 |
Correct |
131 ms |
16120 KB |
Output is correct |
29 |
Correct |
129 ms |
16900 KB |
Output is correct |
30 |
Correct |
127 ms |
16068 KB |
Output is correct |
31 |
Correct |
129 ms |
16640 KB |
Output is correct |
32 |
Correct |
127 ms |
16068 KB |
Output is correct |
33 |
Correct |
127 ms |
16068 KB |
Output is correct |
34 |
Correct |
119 ms |
16620 KB |
Output is correct |
35 |
Correct |
122 ms |
15784 KB |
Output is correct |
36 |
Correct |
119 ms |
15572 KB |
Output is correct |
37 |
Correct |
123 ms |
15624 KB |
Output is correct |
38 |
Correct |
119 ms |
15804 KB |
Output is correct |
39 |
Correct |
125 ms |
18104 KB |
Output is correct |
40 |
Correct |
99 ms |
14268 KB |
Output is correct |
41 |
Correct |
130 ms |
18468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2448 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 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 |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 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 |
2652 KB |
Output is correct |
14 |
Correct |
4 ms |
2784 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 |
2792 KB |
Output is correct |
19 |
Correct |
888 ms |
50280 KB |
Output is correct |
20 |
Correct |
888 ms |
50024 KB |
Output is correct |
21 |
Correct |
994 ms |
82816 KB |
Output is correct |
22 |
Correct |
889 ms |
82524 KB |
Output is correct |
23 |
Correct |
662 ms |
63360 KB |
Output is correct |
24 |
Correct |
75 ms |
7360 KB |
Output is correct |
25 |
Correct |
73 ms |
9264 KB |
Output is correct |
26 |
Correct |
57 ms |
6868 KB |
Output is correct |
27 |
Correct |
55 ms |
6856 KB |
Output is correct |
28 |
Correct |
55 ms |
6888 KB |
Output is correct |
29 |
Correct |
60 ms |
7124 KB |
Output is correct |
30 |
Correct |
55 ms |
7112 KB |
Output is correct |
31 |
Correct |
61 ms |
8200 KB |
Output is correct |
32 |
Correct |
35 ms |
5544 KB |
Output is correct |
33 |
Correct |
59 ms |
7760 KB |
Output is correct |
34 |
Correct |
168 ms |
19392 KB |
Output is correct |
35 |
Correct |
173 ms |
21792 KB |
Output is correct |
36 |
Correct |
174 ms |
20916 KB |
Output is correct |
37 |
Correct |
155 ms |
20152 KB |
Output is correct |
38 |
Correct |
158 ms |
21176 KB |
Output is correct |
39 |
Correct |
123 ms |
15812 KB |
Output is correct |
40 |
Correct |
123 ms |
15900 KB |
Output is correct |
41 |
Correct |
123 ms |
16064 KB |
Output is correct |
42 |
Correct |
124 ms |
16468 KB |
Output is correct |
43 |
Correct |
131 ms |
16120 KB |
Output is correct |
44 |
Correct |
129 ms |
16900 KB |
Output is correct |
45 |
Correct |
127 ms |
16068 KB |
Output is correct |
46 |
Correct |
129 ms |
16640 KB |
Output is correct |
47 |
Correct |
127 ms |
16068 KB |
Output is correct |
48 |
Correct |
127 ms |
16068 KB |
Output is correct |
49 |
Correct |
119 ms |
16620 KB |
Output is correct |
50 |
Correct |
122 ms |
15784 KB |
Output is correct |
51 |
Correct |
119 ms |
15572 KB |
Output is correct |
52 |
Correct |
123 ms |
15624 KB |
Output is correct |
53 |
Correct |
119 ms |
15804 KB |
Output is correct |
54 |
Correct |
125 ms |
18104 KB |
Output is correct |
55 |
Correct |
99 ms |
14268 KB |
Output is correct |
56 |
Correct |
130 ms |
18468 KB |
Output is correct |
57 |
Correct |
917 ms |
82884 KB |
Output is correct |
58 |
Correct |
908 ms |
84048 KB |
Output is correct |
59 |
Correct |
941 ms |
83692 KB |
Output is correct |
60 |
Correct |
905 ms |
83016 KB |
Output is correct |
61 |
Correct |
894 ms |
83880 KB |
Output is correct |
62 |
Correct |
894 ms |
82992 KB |
Output is correct |
63 |
Correct |
651 ms |
63324 KB |
Output is correct |
64 |
Correct |
635 ms |
63156 KB |
Output is correct |
65 |
Correct |
670 ms |
63408 KB |
Output is correct |
66 |
Correct |
660 ms |
63472 KB |
Output is correct |
67 |
Correct |
659 ms |
63668 KB |
Output is correct |
68 |
Correct |
660 ms |
63412 KB |
Output is correct |
69 |
Correct |
661 ms |
63408 KB |
Output is correct |
70 |
Correct |
658 ms |
63600 KB |
Output is correct |
71 |
Correct |
654 ms |
63588 KB |
Output is correct |
72 |
Correct |
658 ms |
63408 KB |
Output is correct |
73 |
Correct |
623 ms |
59996 KB |
Output is correct |
74 |
Correct |
637 ms |
60908 KB |
Output is correct |
75 |
Correct |
632 ms |
59932 KB |
Output is correct |
76 |
Correct |
647 ms |
60684 KB |
Output is correct |
77 |
Correct |
654 ms |
60088 KB |
Output is correct |
78 |
Correct |
686 ms |
65968 KB |
Output is correct |
79 |
Correct |
530 ms |
59316 KB |
Output is correct |
80 |
Correct |
724 ms |
70632 KB |
Output is correct |