#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int mxN=1e6;
int n, m, w[mxN], st[1<<21];
vector<ar<int, 3>> queries[mxN];
bool ans[mxN];
void upd(int i, int x, int u=1, int l=0, int r=n-1) {
if (l==r) {
st[u]=x;
return;
}
int mid=(l+r)/2;
i<=mid?upd(i, x, 2*u, l, mid):upd(i, x, 2*u+1, mid+1, r);
st[u]=max(st[2*u], st[2*u+1]);
}
int qry(int ql, int qr, int u=1, int l=0, int r=n-1) {
if (l>qr||r<ql)
return 0;
if (ql<=l&&r<=qr)
return st[u];
int mid=(l+r)/2;
return max(qry(ql, qr, 2*u, l, mid), qry(ql, qr, 2*u+1, mid+1, r));
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i=0; i<n; ++i)
cin >> w[i];
for (int i=0; i<m; ++i) {
int l, r, k;
cin >> l >> r >> k, --l, --r;
queries[r].push_back({l, k, i});
}
vector<int> st;
for (int i=0; i<n; ++i) {
while(st.size()&&w[i]>=w[st.back()])
st.pop_back();
if (st.size())
upd(st.back(), w[i]+w[st.back()]);
for (auto [l, k, ind] : queries[i])
ans[ind]=qry(l, i)<=k;
st.push_back(i);
}
for (int i=0; i<m; ++i)
cout << ans[i] << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23816 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23712 KB |
Output is correct |
5 |
Correct |
12 ms |
23796 KB |
Output is correct |
6 |
Correct |
12 ms |
23764 KB |
Output is correct |
7 |
Correct |
13 ms |
23788 KB |
Output is correct |
8 |
Correct |
13 ms |
23848 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23816 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23712 KB |
Output is correct |
5 |
Correct |
12 ms |
23796 KB |
Output is correct |
6 |
Correct |
12 ms |
23764 KB |
Output is correct |
7 |
Correct |
13 ms |
23788 KB |
Output is correct |
8 |
Correct |
13 ms |
23848 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
11 |
Correct |
13 ms |
23892 KB |
Output is correct |
12 |
Correct |
13 ms |
23892 KB |
Output is correct |
13 |
Correct |
14 ms |
24080 KB |
Output is correct |
14 |
Correct |
16 ms |
24148 KB |
Output is correct |
15 |
Correct |
16 ms |
24080 KB |
Output is correct |
16 |
Correct |
16 ms |
24020 KB |
Output is correct |
17 |
Correct |
16 ms |
23996 KB |
Output is correct |
18 |
Correct |
18 ms |
23960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1216 ms |
60612 KB |
Output is correct |
2 |
Correct |
1256 ms |
93376 KB |
Output is correct |
3 |
Correct |
1228 ms |
93396 KB |
Output is correct |
4 |
Correct |
1224 ms |
93380 KB |
Output is correct |
5 |
Correct |
1041 ms |
85224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
27636 KB |
Output is correct |
2 |
Correct |
91 ms |
29448 KB |
Output is correct |
3 |
Correct |
80 ms |
28404 KB |
Output is correct |
4 |
Correct |
87 ms |
28492 KB |
Output is correct |
5 |
Correct |
84 ms |
28516 KB |
Output is correct |
6 |
Correct |
70 ms |
28168 KB |
Output is correct |
7 |
Correct |
70 ms |
28016 KB |
Output is correct |
8 |
Correct |
78 ms |
28128 KB |
Output is correct |
9 |
Correct |
44 ms |
26884 KB |
Output is correct |
10 |
Correct |
77 ms |
28168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23816 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23712 KB |
Output is correct |
5 |
Correct |
12 ms |
23796 KB |
Output is correct |
6 |
Correct |
12 ms |
23764 KB |
Output is correct |
7 |
Correct |
13 ms |
23788 KB |
Output is correct |
8 |
Correct |
13 ms |
23848 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
11 |
Correct |
13 ms |
23892 KB |
Output is correct |
12 |
Correct |
13 ms |
23892 KB |
Output is correct |
13 |
Correct |
14 ms |
24080 KB |
Output is correct |
14 |
Correct |
16 ms |
24148 KB |
Output is correct |
15 |
Correct |
16 ms |
24080 KB |
Output is correct |
16 |
Correct |
16 ms |
24020 KB |
Output is correct |
17 |
Correct |
16 ms |
23996 KB |
Output is correct |
18 |
Correct |
18 ms |
23960 KB |
Output is correct |
19 |
Correct |
216 ms |
38044 KB |
Output is correct |
20 |
Correct |
221 ms |
38076 KB |
Output is correct |
21 |
Correct |
208 ms |
37444 KB |
Output is correct |
22 |
Correct |
193 ms |
37380 KB |
Output is correct |
23 |
Correct |
182 ms |
37336 KB |
Output is correct |
24 |
Correct |
172 ms |
35184 KB |
Output is correct |
25 |
Correct |
169 ms |
35108 KB |
Output is correct |
26 |
Correct |
167 ms |
35560 KB |
Output is correct |
27 |
Correct |
173 ms |
35652 KB |
Output is correct |
28 |
Correct |
174 ms |
35644 KB |
Output is correct |
29 |
Correct |
177 ms |
35916 KB |
Output is correct |
30 |
Correct |
190 ms |
35960 KB |
Output is correct |
31 |
Correct |
184 ms |
35932 KB |
Output is correct |
32 |
Correct |
183 ms |
35916 KB |
Output is correct |
33 |
Correct |
187 ms |
35932 KB |
Output is correct |
34 |
Correct |
149 ms |
34704 KB |
Output is correct |
35 |
Correct |
147 ms |
34716 KB |
Output is correct |
36 |
Correct |
148 ms |
34572 KB |
Output is correct |
37 |
Correct |
147 ms |
34596 KB |
Output is correct |
38 |
Correct |
145 ms |
34784 KB |
Output is correct |
39 |
Correct |
161 ms |
34868 KB |
Output is correct |
40 |
Correct |
128 ms |
32896 KB |
Output is correct |
41 |
Correct |
159 ms |
33924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23816 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23712 KB |
Output is correct |
5 |
Correct |
12 ms |
23796 KB |
Output is correct |
6 |
Correct |
12 ms |
23764 KB |
Output is correct |
7 |
Correct |
13 ms |
23788 KB |
Output is correct |
8 |
Correct |
13 ms |
23848 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
11 |
Correct |
13 ms |
23892 KB |
Output is correct |
12 |
Correct |
13 ms |
23892 KB |
Output is correct |
13 |
Correct |
14 ms |
24080 KB |
Output is correct |
14 |
Correct |
16 ms |
24148 KB |
Output is correct |
15 |
Correct |
16 ms |
24080 KB |
Output is correct |
16 |
Correct |
16 ms |
24020 KB |
Output is correct |
17 |
Correct |
16 ms |
23996 KB |
Output is correct |
18 |
Correct |
18 ms |
23960 KB |
Output is correct |
19 |
Correct |
1216 ms |
60612 KB |
Output is correct |
20 |
Correct |
1256 ms |
93376 KB |
Output is correct |
21 |
Correct |
1228 ms |
93396 KB |
Output is correct |
22 |
Correct |
1224 ms |
93380 KB |
Output is correct |
23 |
Correct |
1041 ms |
85224 KB |
Output is correct |
24 |
Correct |
110 ms |
27636 KB |
Output is correct |
25 |
Correct |
91 ms |
29448 KB |
Output is correct |
26 |
Correct |
80 ms |
28404 KB |
Output is correct |
27 |
Correct |
87 ms |
28492 KB |
Output is correct |
28 |
Correct |
84 ms |
28516 KB |
Output is correct |
29 |
Correct |
70 ms |
28168 KB |
Output is correct |
30 |
Correct |
70 ms |
28016 KB |
Output is correct |
31 |
Correct |
78 ms |
28128 KB |
Output is correct |
32 |
Correct |
44 ms |
26884 KB |
Output is correct |
33 |
Correct |
77 ms |
28168 KB |
Output is correct |
34 |
Correct |
216 ms |
38044 KB |
Output is correct |
35 |
Correct |
221 ms |
38076 KB |
Output is correct |
36 |
Correct |
208 ms |
37444 KB |
Output is correct |
37 |
Correct |
193 ms |
37380 KB |
Output is correct |
38 |
Correct |
182 ms |
37336 KB |
Output is correct |
39 |
Correct |
172 ms |
35184 KB |
Output is correct |
40 |
Correct |
169 ms |
35108 KB |
Output is correct |
41 |
Correct |
167 ms |
35560 KB |
Output is correct |
42 |
Correct |
173 ms |
35652 KB |
Output is correct |
43 |
Correct |
174 ms |
35644 KB |
Output is correct |
44 |
Correct |
177 ms |
35916 KB |
Output is correct |
45 |
Correct |
190 ms |
35960 KB |
Output is correct |
46 |
Correct |
184 ms |
35932 KB |
Output is correct |
47 |
Correct |
183 ms |
35916 KB |
Output is correct |
48 |
Correct |
187 ms |
35932 KB |
Output is correct |
49 |
Correct |
149 ms |
34704 KB |
Output is correct |
50 |
Correct |
147 ms |
34716 KB |
Output is correct |
51 |
Correct |
148 ms |
34572 KB |
Output is correct |
52 |
Correct |
147 ms |
34596 KB |
Output is correct |
53 |
Correct |
145 ms |
34784 KB |
Output is correct |
54 |
Correct |
161 ms |
34868 KB |
Output is correct |
55 |
Correct |
128 ms |
32896 KB |
Output is correct |
56 |
Correct |
159 ms |
33924 KB |
Output is correct |
57 |
Correct |
1246 ms |
93680 KB |
Output is correct |
58 |
Correct |
1211 ms |
93528 KB |
Output is correct |
59 |
Correct |
1142 ms |
92000 KB |
Output is correct |
60 |
Correct |
1135 ms |
92044 KB |
Output is correct |
61 |
Correct |
1116 ms |
92004 KB |
Output is correct |
62 |
Correct |
1159 ms |
92104 KB |
Output is correct |
63 |
Correct |
753 ms |
80780 KB |
Output is correct |
64 |
Correct |
760 ms |
80576 KB |
Output is correct |
65 |
Correct |
975 ms |
83744 KB |
Output is correct |
66 |
Correct |
1033 ms |
83732 KB |
Output is correct |
67 |
Correct |
983 ms |
83808 KB |
Output is correct |
68 |
Correct |
1026 ms |
85452 KB |
Output is correct |
69 |
Correct |
1078 ms |
85348 KB |
Output is correct |
70 |
Correct |
1025 ms |
85044 KB |
Output is correct |
71 |
Correct |
1037 ms |
85156 KB |
Output is correct |
72 |
Correct |
1034 ms |
85300 KB |
Output is correct |
73 |
Correct |
692 ms |
76572 KB |
Output is correct |
74 |
Correct |
734 ms |
77548 KB |
Output is correct |
75 |
Correct |
700 ms |
76528 KB |
Output is correct |
76 |
Correct |
730 ms |
76904 KB |
Output is correct |
77 |
Correct |
702 ms |
76364 KB |
Output is correct |
78 |
Correct |
921 ms |
80304 KB |
Output is correct |
79 |
Correct |
673 ms |
68776 KB |
Output is correct |
80 |
Correct |
888 ms |
74776 KB |
Output is correct |