#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() {
ios_base::sync_with_stdio(0);
cout.tie(NULL);
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 |
10 ms |
53852 KB |
Output is correct |
2 |
Correct |
11 ms |
53852 KB |
Output is correct |
3 |
Correct |
12 ms |
53948 KB |
Output is correct |
4 |
Correct |
11 ms |
53852 KB |
Output is correct |
5 |
Correct |
11 ms |
53920 KB |
Output is correct |
6 |
Correct |
12 ms |
54260 KB |
Output is correct |
7 |
Correct |
12 ms |
53852 KB |
Output is correct |
8 |
Correct |
12 ms |
53852 KB |
Output is correct |
9 |
Correct |
14 ms |
53852 KB |
Output is correct |
10 |
Correct |
11 ms |
53852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
53852 KB |
Output is correct |
2 |
Correct |
11 ms |
53852 KB |
Output is correct |
3 |
Correct |
12 ms |
53948 KB |
Output is correct |
4 |
Correct |
11 ms |
53852 KB |
Output is correct |
5 |
Correct |
11 ms |
53920 KB |
Output is correct |
6 |
Correct |
12 ms |
54260 KB |
Output is correct |
7 |
Correct |
12 ms |
53852 KB |
Output is correct |
8 |
Correct |
12 ms |
53852 KB |
Output is correct |
9 |
Correct |
14 ms |
53852 KB |
Output is correct |
10 |
Correct |
11 ms |
53852 KB |
Output is correct |
11 |
Correct |
12 ms |
53852 KB |
Output is correct |
12 |
Correct |
13 ms |
54108 KB |
Output is correct |
13 |
Correct |
14 ms |
54108 KB |
Output is correct |
14 |
Correct |
14 ms |
54108 KB |
Output is correct |
15 |
Correct |
15 ms |
54108 KB |
Output is correct |
16 |
Correct |
14 ms |
54104 KB |
Output is correct |
17 |
Correct |
15 ms |
54108 KB |
Output is correct |
18 |
Correct |
14 ms |
54164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1228 ms |
117304 KB |
Output is correct |
2 |
Correct |
1282 ms |
117328 KB |
Output is correct |
3 |
Correct |
1224 ms |
133964 KB |
Output is correct |
4 |
Correct |
1194 ms |
133932 KB |
Output is correct |
5 |
Correct |
1010 ms |
121844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
61008 KB |
Output is correct |
2 |
Correct |
84 ms |
60496 KB |
Output is correct |
3 |
Correct |
68 ms |
59668 KB |
Output is correct |
4 |
Correct |
95 ms |
60088 KB |
Output is correct |
5 |
Correct |
74 ms |
58312 KB |
Output is correct |
6 |
Correct |
65 ms |
59040 KB |
Output is correct |
7 |
Correct |
57 ms |
59084 KB |
Output is correct |
8 |
Correct |
87 ms |
59156 KB |
Output is correct |
9 |
Correct |
41 ms |
56020 KB |
Output is correct |
10 |
Correct |
69 ms |
59340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
53852 KB |
Output is correct |
2 |
Correct |
11 ms |
53852 KB |
Output is correct |
3 |
Correct |
12 ms |
53948 KB |
Output is correct |
4 |
Correct |
11 ms |
53852 KB |
Output is correct |
5 |
Correct |
11 ms |
53920 KB |
Output is correct |
6 |
Correct |
12 ms |
54260 KB |
Output is correct |
7 |
Correct |
12 ms |
53852 KB |
Output is correct |
8 |
Correct |
12 ms |
53852 KB |
Output is correct |
9 |
Correct |
14 ms |
53852 KB |
Output is correct |
10 |
Correct |
11 ms |
53852 KB |
Output is correct |
11 |
Correct |
12 ms |
53852 KB |
Output is correct |
12 |
Correct |
13 ms |
54108 KB |
Output is correct |
13 |
Correct |
14 ms |
54108 KB |
Output is correct |
14 |
Correct |
14 ms |
54108 KB |
Output is correct |
15 |
Correct |
15 ms |
54108 KB |
Output is correct |
16 |
Correct |
14 ms |
54104 KB |
Output is correct |
17 |
Correct |
15 ms |
54108 KB |
Output is correct |
18 |
Correct |
14 ms |
54164 KB |
Output is correct |
19 |
Correct |
219 ms |
75612 KB |
Output is correct |
20 |
Correct |
205 ms |
75496 KB |
Output is correct |
21 |
Correct |
173 ms |
64268 KB |
Output is correct |
22 |
Correct |
173 ms |
71292 KB |
Output is correct |
23 |
Correct |
211 ms |
73780 KB |
Output is correct |
24 |
Correct |
139 ms |
71588 KB |
Output is correct |
25 |
Correct |
122 ms |
71368 KB |
Output is correct |
26 |
Correct |
161 ms |
72252 KB |
Output is correct |
27 |
Correct |
141 ms |
72576 KB |
Output is correct |
28 |
Correct |
146 ms |
72504 KB |
Output is correct |
29 |
Correct |
170 ms |
73264 KB |
Output is correct |
30 |
Correct |
162 ms |
73300 KB |
Output is correct |
31 |
Correct |
149 ms |
73048 KB |
Output is correct |
32 |
Correct |
158 ms |
73140 KB |
Output is correct |
33 |
Correct |
152 ms |
63688 KB |
Output is correct |
34 |
Correct |
123 ms |
70940 KB |
Output is correct |
35 |
Correct |
114 ms |
71120 KB |
Output is correct |
36 |
Correct |
117 ms |
71244 KB |
Output is correct |
37 |
Correct |
131 ms |
71116 KB |
Output is correct |
38 |
Correct |
136 ms |
70992 KB |
Output is correct |
39 |
Correct |
149 ms |
67048 KB |
Output is correct |
40 |
Correct |
108 ms |
68700 KB |
Output is correct |
41 |
Correct |
143 ms |
71224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
53852 KB |
Output is correct |
2 |
Correct |
11 ms |
53852 KB |
Output is correct |
3 |
Correct |
12 ms |
53948 KB |
Output is correct |
4 |
Correct |
11 ms |
53852 KB |
Output is correct |
5 |
Correct |
11 ms |
53920 KB |
Output is correct |
6 |
Correct |
12 ms |
54260 KB |
Output is correct |
7 |
Correct |
12 ms |
53852 KB |
Output is correct |
8 |
Correct |
12 ms |
53852 KB |
Output is correct |
9 |
Correct |
14 ms |
53852 KB |
Output is correct |
10 |
Correct |
11 ms |
53852 KB |
Output is correct |
11 |
Correct |
12 ms |
53852 KB |
Output is correct |
12 |
Correct |
13 ms |
54108 KB |
Output is correct |
13 |
Correct |
14 ms |
54108 KB |
Output is correct |
14 |
Correct |
14 ms |
54108 KB |
Output is correct |
15 |
Correct |
15 ms |
54108 KB |
Output is correct |
16 |
Correct |
14 ms |
54104 KB |
Output is correct |
17 |
Correct |
15 ms |
54108 KB |
Output is correct |
18 |
Correct |
14 ms |
54164 KB |
Output is correct |
19 |
Correct |
1228 ms |
117304 KB |
Output is correct |
20 |
Correct |
1282 ms |
117328 KB |
Output is correct |
21 |
Correct |
1224 ms |
133964 KB |
Output is correct |
22 |
Correct |
1194 ms |
133932 KB |
Output is correct |
23 |
Correct |
1010 ms |
121844 KB |
Output is correct |
24 |
Correct |
91 ms |
61008 KB |
Output is correct |
25 |
Correct |
84 ms |
60496 KB |
Output is correct |
26 |
Correct |
68 ms |
59668 KB |
Output is correct |
27 |
Correct |
95 ms |
60088 KB |
Output is correct |
28 |
Correct |
74 ms |
58312 KB |
Output is correct |
29 |
Correct |
65 ms |
59040 KB |
Output is correct |
30 |
Correct |
57 ms |
59084 KB |
Output is correct |
31 |
Correct |
87 ms |
59156 KB |
Output is correct |
32 |
Correct |
41 ms |
56020 KB |
Output is correct |
33 |
Correct |
69 ms |
59340 KB |
Output is correct |
34 |
Correct |
219 ms |
75612 KB |
Output is correct |
35 |
Correct |
205 ms |
75496 KB |
Output is correct |
36 |
Correct |
173 ms |
64268 KB |
Output is correct |
37 |
Correct |
173 ms |
71292 KB |
Output is correct |
38 |
Correct |
211 ms |
73780 KB |
Output is correct |
39 |
Correct |
139 ms |
71588 KB |
Output is correct |
40 |
Correct |
122 ms |
71368 KB |
Output is correct |
41 |
Correct |
161 ms |
72252 KB |
Output is correct |
42 |
Correct |
141 ms |
72576 KB |
Output is correct |
43 |
Correct |
146 ms |
72504 KB |
Output is correct |
44 |
Correct |
170 ms |
73264 KB |
Output is correct |
45 |
Correct |
162 ms |
73300 KB |
Output is correct |
46 |
Correct |
149 ms |
73048 KB |
Output is correct |
47 |
Correct |
158 ms |
73140 KB |
Output is correct |
48 |
Correct |
152 ms |
63688 KB |
Output is correct |
49 |
Correct |
123 ms |
70940 KB |
Output is correct |
50 |
Correct |
114 ms |
71120 KB |
Output is correct |
51 |
Correct |
117 ms |
71244 KB |
Output is correct |
52 |
Correct |
131 ms |
71116 KB |
Output is correct |
53 |
Correct |
136 ms |
70992 KB |
Output is correct |
54 |
Correct |
149 ms |
67048 KB |
Output is correct |
55 |
Correct |
108 ms |
68700 KB |
Output is correct |
56 |
Correct |
143 ms |
71224 KB |
Output is correct |
57 |
Correct |
1199 ms |
135668 KB |
Output is correct |
58 |
Correct |
1271 ms |
135640 KB |
Output is correct |
59 |
Correct |
1153 ms |
131512 KB |
Output is correct |
60 |
Correct |
1144 ms |
131600 KB |
Output is correct |
61 |
Correct |
1103 ms |
131520 KB |
Output is correct |
62 |
Correct |
1086 ms |
131712 KB |
Output is correct |
63 |
Correct |
564 ms |
112856 KB |
Output is correct |
64 |
Correct |
580 ms |
112660 KB |
Output is correct |
65 |
Correct |
831 ms |
119632 KB |
Output is correct |
66 |
Correct |
842 ms |
119964 KB |
Output is correct |
67 |
Correct |
853 ms |
103264 KB |
Output is correct |
68 |
Correct |
882 ms |
106544 KB |
Output is correct |
69 |
Correct |
887 ms |
106548 KB |
Output is correct |
70 |
Correct |
908 ms |
105820 KB |
Output is correct |
71 |
Correct |
932 ms |
106044 KB |
Output is correct |
72 |
Correct |
894 ms |
105844 KB |
Output is correct |
73 |
Correct |
545 ms |
96204 KB |
Output is correct |
74 |
Correct |
544 ms |
96440 KB |
Output is correct |
75 |
Correct |
524 ms |
96200 KB |
Output is correct |
76 |
Correct |
519 ms |
96424 KB |
Output is correct |
77 |
Correct |
531 ms |
96564 KB |
Output is correct |
78 |
Correct |
804 ms |
105128 KB |
Output is correct |
79 |
Correct |
531 ms |
97460 KB |
Output is correct |
80 |
Correct |
797 ms |
102164 KB |
Output is correct |