#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int N = 1e6+10;
const int INF = 1e9+100;
int w[N], k[N], lf[N], x[N], n, q;
vector<pii> v[N];
vector<int> evs[N];
struct segtree {
vector<int> t;
void init(int k) {
int sz=1;
while (sz < 4*k) sz*=2;
t.resize(sz);
}
void upd(int v, int l, int r, int p, int val) {
if (l == r) {
t[v]=val;
return;
} int m=(l+r)/2;
if (p <= m) upd(2*v, l, m, p, val);
else upd(2*v+1, m+1, r, p, val);
t[v]=max(t[2*v], t[2*v+1]);
}
int que(int v, int l, int r, int ql, int qr) {
if (l > qr || r < ql) return 0;
if (l >= ql && r <= qr) return t[v];
int m=(l+r)/2;
return max(que(2*v, l, m, ql, qr), que(2*v+1, m+1, r, ql, qr));
}
};
int main() {
cin>>n>>q;
for (int i=1; i<=n; ++i) cin>>w[i];
for (int i=1; i<=q; ++i) {
int l, r; cin>>l>>r>>k[i];
v[l].push_back({r, i});
}
segtree t; t.init(n+10);
w[0]=INF;
stack<int> st; st.push(0);
for (int i=1; i<=n; ++i) {
while (w[st.top()] <= w[i]) st.pop();
lf[i]=st.top(); evs[st.top()].push_back(i);
if (lf[i] > 0) t.upd(1, 1, n, i, w[st.top()]+w[i]);
st.push(i);
}
for (int i=1; i<=n; ++i) {
for (auto u : v[i]) x[u.second]=t.que(1, 1, n, i, u.first);
for (auto u : evs[i]) t.upd(1, 1, n, u, 0);
}
for (int i=1; i<=q; ++i) {
if (x[i] > k[i]) cout<<0<<"\n";
else cout<<1<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
53848 KB |
Output is correct |
2 |
Correct |
11 ms |
53852 KB |
Output is correct |
3 |
Correct |
11 ms |
53852 KB |
Output is correct |
4 |
Correct |
11 ms |
53852 KB |
Output is correct |
5 |
Correct |
11 ms |
53852 KB |
Output is correct |
6 |
Correct |
11 ms |
53900 KB |
Output is correct |
7 |
Correct |
11 ms |
53848 KB |
Output is correct |
8 |
Correct |
11 ms |
53852 KB |
Output is correct |
9 |
Correct |
11 ms |
53852 KB |
Output is correct |
10 |
Correct |
12 ms |
53848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
53848 KB |
Output is correct |
2 |
Correct |
11 ms |
53852 KB |
Output is correct |
3 |
Correct |
11 ms |
53852 KB |
Output is correct |
4 |
Correct |
11 ms |
53852 KB |
Output is correct |
5 |
Correct |
11 ms |
53852 KB |
Output is correct |
6 |
Correct |
11 ms |
53900 KB |
Output is correct |
7 |
Correct |
11 ms |
53848 KB |
Output is correct |
8 |
Correct |
11 ms |
53852 KB |
Output is correct |
9 |
Correct |
11 ms |
53852 KB |
Output is correct |
10 |
Correct |
12 ms |
53848 KB |
Output is correct |
11 |
Correct |
15 ms |
54108 KB |
Output is correct |
12 |
Correct |
15 ms |
54252 KB |
Output is correct |
13 |
Correct |
16 ms |
54364 KB |
Output is correct |
14 |
Correct |
18 ms |
54192 KB |
Output is correct |
15 |
Correct |
18 ms |
54364 KB |
Output is correct |
16 |
Correct |
16 ms |
54108 KB |
Output is correct |
17 |
Correct |
16 ms |
54104 KB |
Output is correct |
18 |
Correct |
19 ms |
54220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1803 ms |
117476 KB |
Output is correct |
2 |
Correct |
1830 ms |
150288 KB |
Output is correct |
3 |
Correct |
1868 ms |
150276 KB |
Output is correct |
4 |
Correct |
1885 ms |
150164 KB |
Output is correct |
5 |
Correct |
1608 ms |
137996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
148 ms |
59824 KB |
Output is correct |
2 |
Correct |
133 ms |
61136 KB |
Output is correct |
3 |
Correct |
115 ms |
60368 KB |
Output is correct |
4 |
Correct |
152 ms |
60628 KB |
Output is correct |
5 |
Correct |
120 ms |
60612 KB |
Output is correct |
6 |
Correct |
102 ms |
59608 KB |
Output is correct |
7 |
Correct |
101 ms |
59608 KB |
Output is correct |
8 |
Correct |
111 ms |
59808 KB |
Output is correct |
9 |
Correct |
71 ms |
56264 KB |
Output is correct |
10 |
Correct |
110 ms |
60020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
53848 KB |
Output is correct |
2 |
Correct |
11 ms |
53852 KB |
Output is correct |
3 |
Correct |
11 ms |
53852 KB |
Output is correct |
4 |
Correct |
11 ms |
53852 KB |
Output is correct |
5 |
Correct |
11 ms |
53852 KB |
Output is correct |
6 |
Correct |
11 ms |
53900 KB |
Output is correct |
7 |
Correct |
11 ms |
53848 KB |
Output is correct |
8 |
Correct |
11 ms |
53852 KB |
Output is correct |
9 |
Correct |
11 ms |
53852 KB |
Output is correct |
10 |
Correct |
12 ms |
53848 KB |
Output is correct |
11 |
Correct |
15 ms |
54108 KB |
Output is correct |
12 |
Correct |
15 ms |
54252 KB |
Output is correct |
13 |
Correct |
16 ms |
54364 KB |
Output is correct |
14 |
Correct |
18 ms |
54192 KB |
Output is correct |
15 |
Correct |
18 ms |
54364 KB |
Output is correct |
16 |
Correct |
16 ms |
54108 KB |
Output is correct |
17 |
Correct |
16 ms |
54104 KB |
Output is correct |
18 |
Correct |
19 ms |
54220 KB |
Output is correct |
19 |
Correct |
393 ms |
78620 KB |
Output is correct |
20 |
Correct |
340 ms |
78540 KB |
Output is correct |
21 |
Correct |
308 ms |
76712 KB |
Output is correct |
22 |
Correct |
345 ms |
76640 KB |
Output is correct |
23 |
Correct |
303 ms |
76644 KB |
Output is correct |
24 |
Correct |
256 ms |
74348 KB |
Output is correct |
25 |
Correct |
254 ms |
74556 KB |
Output is correct |
26 |
Correct |
276 ms |
75276 KB |
Output is correct |
27 |
Correct |
296 ms |
75600 KB |
Output is correct |
28 |
Correct |
279 ms |
75332 KB |
Output is correct |
29 |
Correct |
295 ms |
76232 KB |
Output is correct |
30 |
Correct |
321 ms |
76196 KB |
Output is correct |
31 |
Correct |
290 ms |
76064 KB |
Output is correct |
32 |
Correct |
299 ms |
76236 KB |
Output is correct |
33 |
Correct |
291 ms |
76168 KB |
Output is correct |
34 |
Correct |
250 ms |
73924 KB |
Output is correct |
35 |
Correct |
244 ms |
73928 KB |
Output is correct |
36 |
Correct |
244 ms |
73672 KB |
Output is correct |
37 |
Correct |
241 ms |
73756 KB |
Output is correct |
38 |
Correct |
285 ms |
73816 KB |
Output is correct |
39 |
Correct |
249 ms |
74308 KB |
Output is correct |
40 |
Correct |
212 ms |
70600 KB |
Output is correct |
41 |
Correct |
248 ms |
73508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
53848 KB |
Output is correct |
2 |
Correct |
11 ms |
53852 KB |
Output is correct |
3 |
Correct |
11 ms |
53852 KB |
Output is correct |
4 |
Correct |
11 ms |
53852 KB |
Output is correct |
5 |
Correct |
11 ms |
53852 KB |
Output is correct |
6 |
Correct |
11 ms |
53900 KB |
Output is correct |
7 |
Correct |
11 ms |
53848 KB |
Output is correct |
8 |
Correct |
11 ms |
53852 KB |
Output is correct |
9 |
Correct |
11 ms |
53852 KB |
Output is correct |
10 |
Correct |
12 ms |
53848 KB |
Output is correct |
11 |
Correct |
15 ms |
54108 KB |
Output is correct |
12 |
Correct |
15 ms |
54252 KB |
Output is correct |
13 |
Correct |
16 ms |
54364 KB |
Output is correct |
14 |
Correct |
18 ms |
54192 KB |
Output is correct |
15 |
Correct |
18 ms |
54364 KB |
Output is correct |
16 |
Correct |
16 ms |
54108 KB |
Output is correct |
17 |
Correct |
16 ms |
54104 KB |
Output is correct |
18 |
Correct |
19 ms |
54220 KB |
Output is correct |
19 |
Correct |
1803 ms |
117476 KB |
Output is correct |
20 |
Correct |
1830 ms |
150288 KB |
Output is correct |
21 |
Correct |
1868 ms |
150276 KB |
Output is correct |
22 |
Correct |
1885 ms |
150164 KB |
Output is correct |
23 |
Correct |
1608 ms |
137996 KB |
Output is correct |
24 |
Correct |
148 ms |
59824 KB |
Output is correct |
25 |
Correct |
133 ms |
61136 KB |
Output is correct |
26 |
Correct |
115 ms |
60368 KB |
Output is correct |
27 |
Correct |
152 ms |
60628 KB |
Output is correct |
28 |
Correct |
120 ms |
60612 KB |
Output is correct |
29 |
Correct |
102 ms |
59608 KB |
Output is correct |
30 |
Correct |
101 ms |
59608 KB |
Output is correct |
31 |
Correct |
111 ms |
59808 KB |
Output is correct |
32 |
Correct |
71 ms |
56264 KB |
Output is correct |
33 |
Correct |
110 ms |
60020 KB |
Output is correct |
34 |
Correct |
393 ms |
78620 KB |
Output is correct |
35 |
Correct |
340 ms |
78540 KB |
Output is correct |
36 |
Correct |
308 ms |
76712 KB |
Output is correct |
37 |
Correct |
345 ms |
76640 KB |
Output is correct |
38 |
Correct |
303 ms |
76644 KB |
Output is correct |
39 |
Correct |
256 ms |
74348 KB |
Output is correct |
40 |
Correct |
254 ms |
74556 KB |
Output is correct |
41 |
Correct |
276 ms |
75276 KB |
Output is correct |
42 |
Correct |
296 ms |
75600 KB |
Output is correct |
43 |
Correct |
279 ms |
75332 KB |
Output is correct |
44 |
Correct |
295 ms |
76232 KB |
Output is correct |
45 |
Correct |
321 ms |
76196 KB |
Output is correct |
46 |
Correct |
290 ms |
76064 KB |
Output is correct |
47 |
Correct |
299 ms |
76236 KB |
Output is correct |
48 |
Correct |
291 ms |
76168 KB |
Output is correct |
49 |
Correct |
250 ms |
73924 KB |
Output is correct |
50 |
Correct |
244 ms |
73928 KB |
Output is correct |
51 |
Correct |
244 ms |
73672 KB |
Output is correct |
52 |
Correct |
241 ms |
73756 KB |
Output is correct |
53 |
Correct |
285 ms |
73816 KB |
Output is correct |
54 |
Correct |
249 ms |
74308 KB |
Output is correct |
55 |
Correct |
212 ms |
70600 KB |
Output is correct |
56 |
Correct |
248 ms |
73508 KB |
Output is correct |
57 |
Correct |
1936 ms |
152292 KB |
Output is correct |
58 |
Correct |
1947 ms |
152160 KB |
Output is correct |
59 |
Correct |
1783 ms |
148160 KB |
Output is correct |
60 |
Correct |
1800 ms |
148220 KB |
Output is correct |
61 |
Correct |
1771 ms |
148236 KB |
Output is correct |
62 |
Correct |
1774 ms |
148252 KB |
Output is correct |
63 |
Correct |
1320 ms |
128252 KB |
Output is correct |
64 |
Correct |
1214 ms |
128220 KB |
Output is correct |
65 |
Correct |
1670 ms |
136208 KB |
Output is correct |
66 |
Correct |
1699 ms |
136160 KB |
Output is correct |
67 |
Correct |
1728 ms |
136024 KB |
Output is correct |
68 |
Correct |
1758 ms |
140164 KB |
Output is correct |
69 |
Correct |
1737 ms |
140052 KB |
Output is correct |
70 |
Correct |
1819 ms |
139404 KB |
Output is correct |
71 |
Correct |
1772 ms |
139584 KB |
Output is correct |
72 |
Correct |
1791 ms |
139392 KB |
Output is correct |
73 |
Correct |
1221 ms |
126096 KB |
Output is correct |
74 |
Correct |
1324 ms |
127188 KB |
Output is correct |
75 |
Correct |
1295 ms |
126180 KB |
Output is correct |
76 |
Correct |
1229 ms |
126072 KB |
Output is correct |
77 |
Correct |
1223 ms |
126220 KB |
Output is correct |
78 |
Correct |
1517 ms |
132516 KB |
Output is correct |
79 |
Correct |
1160 ms |
119912 KB |
Output is correct |
80 |
Correct |
1498 ms |
127964 KB |
Output is correct |