#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
const int maxn = 1e6 + 69;
int n, q, a[maxn], st[4 * maxn], ans[maxn];
vector<tuple<int, int, int>> g[maxn];
void upd(int v, int tl, int tr, int p, int x) {
if (tl == tr)
st[v] = max(st[v], x);
else {
int mid = (tl + tr) / 2;
if (p <= mid)
upd(v * 2, tl, mid, p, x);
else
upd(v * 2 + 1, mid + 1, tr, p, x);
st[v] = max(st[v * 2], st[v * 2 + 1]);
}
}
int qry(int v, int tl, int tr, int l, int r) {
if (tl > r || tr < l)
return 0;
else if (tl >= l && tr <= r)
return st[v];
else {
int mid = (tl + tr) / 2;
return max(qry(v * 2, tl, mid, l, r), qry(v * 2 + 1, mid + 1, tr, l, r));
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> n >> q;
for (int i = 1;i <= n;i++)
cin >> a[i];
vector<int> stck;
for (int i = 1;i <= q;i++) {
int l, r, k;
cin >> l >> r >> k;
g[r].push_back({l, k, i});
}
for (int i = 1;i <= n;i++) {
while (!stck.empty() && a[stck.back()] <= a[i])
stck.pop_back();
if (!stck.empty())
upd(1, 1, n, stck.back(), a[i] + a[stck.back()]);
for (auto u : g[i]) {
int l, k, ind;
tie(l, k, ind) = u;
ans[ind] = (qry(1, 1, n, l, i) <= k);
}
stck.push_back(i);
}
for (int i = 1;i <= q;i++)
cout << ans[i] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
27224 KB |
Output is correct |
2 |
Correct |
5 ms |
27228 KB |
Output is correct |
3 |
Correct |
6 ms |
27228 KB |
Output is correct |
4 |
Correct |
6 ms |
27228 KB |
Output is correct |
5 |
Correct |
6 ms |
27228 KB |
Output is correct |
6 |
Correct |
6 ms |
27228 KB |
Output is correct |
7 |
Correct |
6 ms |
27228 KB |
Output is correct |
8 |
Correct |
6 ms |
27144 KB |
Output is correct |
9 |
Correct |
6 ms |
27228 KB |
Output is correct |
10 |
Correct |
7 ms |
27252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
27224 KB |
Output is correct |
2 |
Correct |
5 ms |
27228 KB |
Output is correct |
3 |
Correct |
6 ms |
27228 KB |
Output is correct |
4 |
Correct |
6 ms |
27228 KB |
Output is correct |
5 |
Correct |
6 ms |
27228 KB |
Output is correct |
6 |
Correct |
6 ms |
27228 KB |
Output is correct |
7 |
Correct |
6 ms |
27228 KB |
Output is correct |
8 |
Correct |
6 ms |
27144 KB |
Output is correct |
9 |
Correct |
6 ms |
27228 KB |
Output is correct |
10 |
Correct |
7 ms |
27252 KB |
Output is correct |
11 |
Correct |
7 ms |
27480 KB |
Output is correct |
12 |
Correct |
8 ms |
27480 KB |
Output is correct |
13 |
Correct |
8 ms |
27584 KB |
Output is correct |
14 |
Correct |
9 ms |
27736 KB |
Output is correct |
15 |
Correct |
9 ms |
27936 KB |
Output is correct |
16 |
Correct |
8 ms |
27436 KB |
Output is correct |
17 |
Correct |
8 ms |
27584 KB |
Output is correct |
18 |
Correct |
9 ms |
27484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1167 ms |
91268 KB |
Output is correct |
2 |
Correct |
1166 ms |
91464 KB |
Output is correct |
3 |
Correct |
1148 ms |
91228 KB |
Output is correct |
4 |
Correct |
1223 ms |
91268 KB |
Output is correct |
5 |
Correct |
917 ms |
75020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
32592 KB |
Output is correct |
2 |
Correct |
78 ms |
34896 KB |
Output is correct |
3 |
Correct |
70 ms |
32732 KB |
Output is correct |
4 |
Correct |
70 ms |
32592 KB |
Output is correct |
5 |
Correct |
66 ms |
32592 KB |
Output is correct |
6 |
Correct |
56 ms |
32636 KB |
Output is correct |
7 |
Correct |
54 ms |
32592 KB |
Output is correct |
8 |
Correct |
59 ms |
32476 KB |
Output is correct |
9 |
Correct |
35 ms |
31748 KB |
Output is correct |
10 |
Correct |
66 ms |
32528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
27224 KB |
Output is correct |
2 |
Correct |
5 ms |
27228 KB |
Output is correct |
3 |
Correct |
6 ms |
27228 KB |
Output is correct |
4 |
Correct |
6 ms |
27228 KB |
Output is correct |
5 |
Correct |
6 ms |
27228 KB |
Output is correct |
6 |
Correct |
6 ms |
27228 KB |
Output is correct |
7 |
Correct |
6 ms |
27228 KB |
Output is correct |
8 |
Correct |
6 ms |
27144 KB |
Output is correct |
9 |
Correct |
6 ms |
27228 KB |
Output is correct |
10 |
Correct |
7 ms |
27252 KB |
Output is correct |
11 |
Correct |
7 ms |
27480 KB |
Output is correct |
12 |
Correct |
8 ms |
27480 KB |
Output is correct |
13 |
Correct |
8 ms |
27584 KB |
Output is correct |
14 |
Correct |
9 ms |
27736 KB |
Output is correct |
15 |
Correct |
9 ms |
27936 KB |
Output is correct |
16 |
Correct |
8 ms |
27436 KB |
Output is correct |
17 |
Correct |
8 ms |
27584 KB |
Output is correct |
18 |
Correct |
9 ms |
27484 KB |
Output is correct |
19 |
Correct |
183 ms |
48616 KB |
Output is correct |
20 |
Correct |
169 ms |
49164 KB |
Output is correct |
21 |
Correct |
150 ms |
49744 KB |
Output is correct |
22 |
Correct |
148 ms |
49748 KB |
Output is correct |
23 |
Correct |
152 ms |
49748 KB |
Output is correct |
24 |
Correct |
126 ms |
45232 KB |
Output is correct |
25 |
Correct |
125 ms |
45212 KB |
Output is correct |
26 |
Correct |
139 ms |
45092 KB |
Output is correct |
27 |
Correct |
135 ms |
45152 KB |
Output is correct |
28 |
Correct |
152 ms |
44908 KB |
Output is correct |
29 |
Correct |
188 ms |
44808 KB |
Output is correct |
30 |
Correct |
144 ms |
44796 KB |
Output is correct |
31 |
Correct |
149 ms |
44852 KB |
Output is correct |
32 |
Correct |
163 ms |
45148 KB |
Output is correct |
33 |
Correct |
147 ms |
44804 KB |
Output is correct |
34 |
Correct |
118 ms |
44696 KB |
Output is correct |
35 |
Correct |
114 ms |
44688 KB |
Output is correct |
36 |
Correct |
113 ms |
44388 KB |
Output is correct |
37 |
Correct |
112 ms |
44368 KB |
Output is correct |
38 |
Correct |
115 ms |
44588 KB |
Output is correct |
39 |
Correct |
150 ms |
44264 KB |
Output is correct |
40 |
Correct |
101 ms |
39656 KB |
Output is correct |
41 |
Correct |
122 ms |
42332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
27224 KB |
Output is correct |
2 |
Correct |
5 ms |
27228 KB |
Output is correct |
3 |
Correct |
6 ms |
27228 KB |
Output is correct |
4 |
Correct |
6 ms |
27228 KB |
Output is correct |
5 |
Correct |
6 ms |
27228 KB |
Output is correct |
6 |
Correct |
6 ms |
27228 KB |
Output is correct |
7 |
Correct |
6 ms |
27228 KB |
Output is correct |
8 |
Correct |
6 ms |
27144 KB |
Output is correct |
9 |
Correct |
6 ms |
27228 KB |
Output is correct |
10 |
Correct |
7 ms |
27252 KB |
Output is correct |
11 |
Correct |
7 ms |
27480 KB |
Output is correct |
12 |
Correct |
8 ms |
27480 KB |
Output is correct |
13 |
Correct |
8 ms |
27584 KB |
Output is correct |
14 |
Correct |
9 ms |
27736 KB |
Output is correct |
15 |
Correct |
9 ms |
27936 KB |
Output is correct |
16 |
Correct |
8 ms |
27436 KB |
Output is correct |
17 |
Correct |
8 ms |
27584 KB |
Output is correct |
18 |
Correct |
9 ms |
27484 KB |
Output is correct |
19 |
Correct |
1167 ms |
91268 KB |
Output is correct |
20 |
Correct |
1166 ms |
91464 KB |
Output is correct |
21 |
Correct |
1148 ms |
91228 KB |
Output is correct |
22 |
Correct |
1223 ms |
91268 KB |
Output is correct |
23 |
Correct |
917 ms |
75020 KB |
Output is correct |
24 |
Correct |
95 ms |
32592 KB |
Output is correct |
25 |
Correct |
78 ms |
34896 KB |
Output is correct |
26 |
Correct |
70 ms |
32732 KB |
Output is correct |
27 |
Correct |
70 ms |
32592 KB |
Output is correct |
28 |
Correct |
66 ms |
32592 KB |
Output is correct |
29 |
Correct |
56 ms |
32636 KB |
Output is correct |
30 |
Correct |
54 ms |
32592 KB |
Output is correct |
31 |
Correct |
59 ms |
32476 KB |
Output is correct |
32 |
Correct |
35 ms |
31748 KB |
Output is correct |
33 |
Correct |
66 ms |
32528 KB |
Output is correct |
34 |
Correct |
183 ms |
48616 KB |
Output is correct |
35 |
Correct |
169 ms |
49164 KB |
Output is correct |
36 |
Correct |
150 ms |
49744 KB |
Output is correct |
37 |
Correct |
148 ms |
49748 KB |
Output is correct |
38 |
Correct |
152 ms |
49748 KB |
Output is correct |
39 |
Correct |
126 ms |
45232 KB |
Output is correct |
40 |
Correct |
125 ms |
45212 KB |
Output is correct |
41 |
Correct |
139 ms |
45092 KB |
Output is correct |
42 |
Correct |
135 ms |
45152 KB |
Output is correct |
43 |
Correct |
152 ms |
44908 KB |
Output is correct |
44 |
Correct |
188 ms |
44808 KB |
Output is correct |
45 |
Correct |
144 ms |
44796 KB |
Output is correct |
46 |
Correct |
149 ms |
44852 KB |
Output is correct |
47 |
Correct |
163 ms |
45148 KB |
Output is correct |
48 |
Correct |
147 ms |
44804 KB |
Output is correct |
49 |
Correct |
118 ms |
44696 KB |
Output is correct |
50 |
Correct |
114 ms |
44688 KB |
Output is correct |
51 |
Correct |
113 ms |
44388 KB |
Output is correct |
52 |
Correct |
112 ms |
44368 KB |
Output is correct |
53 |
Correct |
115 ms |
44588 KB |
Output is correct |
54 |
Correct |
150 ms |
44264 KB |
Output is correct |
55 |
Correct |
101 ms |
39656 KB |
Output is correct |
56 |
Correct |
122 ms |
42332 KB |
Output is correct |
57 |
Correct |
1149 ms |
125032 KB |
Output is correct |
58 |
Correct |
1135 ms |
124972 KB |
Output is correct |
59 |
Correct |
1036 ms |
125832 KB |
Output is correct |
60 |
Correct |
1029 ms |
125944 KB |
Output is correct |
61 |
Correct |
1113 ms |
125664 KB |
Output is correct |
62 |
Correct |
1142 ms |
125852 KB |
Output is correct |
63 |
Correct |
685 ms |
109576 KB |
Output is correct |
64 |
Correct |
630 ms |
109476 KB |
Output is correct |
65 |
Correct |
905 ms |
109652 KB |
Output is correct |
66 |
Correct |
890 ms |
109412 KB |
Output is correct |
67 |
Correct |
979 ms |
109700 KB |
Output is correct |
68 |
Correct |
991 ms |
108392 KB |
Output is correct |
69 |
Correct |
943 ms |
108568 KB |
Output is correct |
70 |
Correct |
978 ms |
108660 KB |
Output is correct |
71 |
Correct |
1032 ms |
108888 KB |
Output is correct |
72 |
Correct |
995 ms |
109152 KB |
Output is correct |
73 |
Correct |
625 ms |
107348 KB |
Output is correct |
74 |
Correct |
579 ms |
108112 KB |
Output is correct |
75 |
Correct |
594 ms |
106932 KB |
Output is correct |
76 |
Correct |
580 ms |
107548 KB |
Output is correct |
77 |
Correct |
578 ms |
107104 KB |
Output is correct |
78 |
Correct |
834 ms |
105692 KB |
Output is correct |
79 |
Correct |
568 ms |
90832 KB |
Output is correct |
80 |
Correct |
822 ms |
98212 KB |
Output is correct |