#include <bits/stdc++.h>
using namespace std;
#define int long long
#define piii pair<int,pair<int,int>>
#define fi first
#define se second
const int N = 1e6 + 5;
int st[4 * N],a[N],ans[N],f[N];
vector<piii>vec[N];
void update(int id,int l,int r,int i,int val) {
if (i < l || r < i) return;
if (l == r) {
st[id] = val;
return;
}
int mid = (l + r) / 2;
update(id * 2,l,mid,i,val);
update(id * 2 + 1,mid + 1,r,i,val);
st[id] = max(st[id * 2],st[id * 2 + 1]);
}
int get(int id,int l,int r,int u,int v) {
if (v < l || r < u) return 0;
if (u <= l && r <= v) return st[id];
int mid = (l + r) / 2;
return max(get(id * 2,l,mid,u,v),get(id * 2 + 1,mid + 1,r,u,v));
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n,m;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) {
int l,r,k;
cin >> l >> r >> k;
vec[r].push_back({l,{i,k}});
}
stack<int>st;
for (int i = 1; i <= n; i++) {
while (!st.empty() && a[st.top()] <= a[i]) st.pop();
if (!st.empty()) f[i] = st.top();
else f[i] = 0;
st.push(i);
}
for (int r = 1; r <= n; r++) {
if (f[r]) update(1,1,n,f[r],a[f[r]] + a[r]);
for (auto x: vec[r]) {
int l = x.fi,idx = x.se.fi,k = x.se.se;
ans[idx] = (get(1,1,n,l,r) <= k);
}
}
for (int i = 1; i <= m; i++) cout << ans[i] << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
31320 KB |
Output is correct |
2 |
Correct |
6 ms |
29276 KB |
Output is correct |
3 |
Correct |
8 ms |
31452 KB |
Output is correct |
4 |
Correct |
7 ms |
31324 KB |
Output is correct |
5 |
Correct |
6 ms |
31324 KB |
Output is correct |
6 |
Correct |
7 ms |
31324 KB |
Output is correct |
7 |
Correct |
7 ms |
31324 KB |
Output is correct |
8 |
Correct |
6 ms |
29324 KB |
Output is correct |
9 |
Correct |
6 ms |
29276 KB |
Output is correct |
10 |
Correct |
7 ms |
29276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
31320 KB |
Output is correct |
2 |
Correct |
6 ms |
29276 KB |
Output is correct |
3 |
Correct |
8 ms |
31452 KB |
Output is correct |
4 |
Correct |
7 ms |
31324 KB |
Output is correct |
5 |
Correct |
6 ms |
31324 KB |
Output is correct |
6 |
Correct |
7 ms |
31324 KB |
Output is correct |
7 |
Correct |
7 ms |
31324 KB |
Output is correct |
8 |
Correct |
6 ms |
29324 KB |
Output is correct |
9 |
Correct |
6 ms |
29276 KB |
Output is correct |
10 |
Correct |
7 ms |
29276 KB |
Output is correct |
11 |
Correct |
8 ms |
31832 KB |
Output is correct |
12 |
Correct |
9 ms |
33476 KB |
Output is correct |
13 |
Correct |
9 ms |
33636 KB |
Output is correct |
14 |
Correct |
10 ms |
33632 KB |
Output is correct |
15 |
Correct |
10 ms |
33624 KB |
Output is correct |
16 |
Correct |
10 ms |
31580 KB |
Output is correct |
17 |
Correct |
9 ms |
31580 KB |
Output is correct |
18 |
Correct |
10 ms |
31580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1205 ms |
121040 KB |
Output is correct |
2 |
Correct |
1237 ms |
129404 KB |
Output is correct |
3 |
Correct |
1199 ms |
129064 KB |
Output is correct |
4 |
Correct |
1207 ms |
129768 KB |
Output is correct |
5 |
Correct |
999 ms |
113388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
40896 KB |
Output is correct |
2 |
Correct |
76 ms |
40928 KB |
Output is correct |
3 |
Correct |
66 ms |
36880 KB |
Output is correct |
4 |
Correct |
67 ms |
36684 KB |
Output is correct |
5 |
Correct |
69 ms |
36688 KB |
Output is correct |
6 |
Correct |
56 ms |
40788 KB |
Output is correct |
7 |
Correct |
56 ms |
40704 KB |
Output is correct |
8 |
Correct |
63 ms |
36080 KB |
Output is correct |
9 |
Correct |
34 ms |
33796 KB |
Output is correct |
10 |
Correct |
65 ms |
36604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
31320 KB |
Output is correct |
2 |
Correct |
6 ms |
29276 KB |
Output is correct |
3 |
Correct |
8 ms |
31452 KB |
Output is correct |
4 |
Correct |
7 ms |
31324 KB |
Output is correct |
5 |
Correct |
6 ms |
31324 KB |
Output is correct |
6 |
Correct |
7 ms |
31324 KB |
Output is correct |
7 |
Correct |
7 ms |
31324 KB |
Output is correct |
8 |
Correct |
6 ms |
29324 KB |
Output is correct |
9 |
Correct |
6 ms |
29276 KB |
Output is correct |
10 |
Correct |
7 ms |
29276 KB |
Output is correct |
11 |
Correct |
8 ms |
31832 KB |
Output is correct |
12 |
Correct |
9 ms |
33476 KB |
Output is correct |
13 |
Correct |
9 ms |
33636 KB |
Output is correct |
14 |
Correct |
10 ms |
33632 KB |
Output is correct |
15 |
Correct |
10 ms |
33624 KB |
Output is correct |
16 |
Correct |
10 ms |
31580 KB |
Output is correct |
17 |
Correct |
9 ms |
31580 KB |
Output is correct |
18 |
Correct |
10 ms |
31580 KB |
Output is correct |
19 |
Correct |
197 ms |
52560 KB |
Output is correct |
20 |
Correct |
180 ms |
52620 KB |
Output is correct |
21 |
Correct |
171 ms |
53304 KB |
Output is correct |
22 |
Correct |
164 ms |
52876 KB |
Output is correct |
23 |
Correct |
161 ms |
52852 KB |
Output is correct |
24 |
Correct |
131 ms |
46760 KB |
Output is correct |
25 |
Correct |
126 ms |
46676 KB |
Output is correct |
26 |
Correct |
146 ms |
46484 KB |
Output is correct |
27 |
Correct |
140 ms |
46672 KB |
Output is correct |
28 |
Correct |
143 ms |
46576 KB |
Output is correct |
29 |
Correct |
149 ms |
46404 KB |
Output is correct |
30 |
Correct |
151 ms |
46640 KB |
Output is correct |
31 |
Correct |
166 ms |
46548 KB |
Output is correct |
32 |
Correct |
150 ms |
46340 KB |
Output is correct |
33 |
Correct |
149 ms |
46332 KB |
Output is correct |
34 |
Correct |
116 ms |
50112 KB |
Output is correct |
35 |
Correct |
117 ms |
50148 KB |
Output is correct |
36 |
Correct |
116 ms |
50180 KB |
Output is correct |
37 |
Correct |
117 ms |
50240 KB |
Output is correct |
38 |
Correct |
124 ms |
50464 KB |
Output is correct |
39 |
Correct |
151 ms |
46084 KB |
Output is correct |
40 |
Correct |
103 ms |
42156 KB |
Output is correct |
41 |
Correct |
139 ms |
45268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
31320 KB |
Output is correct |
2 |
Correct |
6 ms |
29276 KB |
Output is correct |
3 |
Correct |
8 ms |
31452 KB |
Output is correct |
4 |
Correct |
7 ms |
31324 KB |
Output is correct |
5 |
Correct |
6 ms |
31324 KB |
Output is correct |
6 |
Correct |
7 ms |
31324 KB |
Output is correct |
7 |
Correct |
7 ms |
31324 KB |
Output is correct |
8 |
Correct |
6 ms |
29324 KB |
Output is correct |
9 |
Correct |
6 ms |
29276 KB |
Output is correct |
10 |
Correct |
7 ms |
29276 KB |
Output is correct |
11 |
Correct |
8 ms |
31832 KB |
Output is correct |
12 |
Correct |
9 ms |
33476 KB |
Output is correct |
13 |
Correct |
9 ms |
33636 KB |
Output is correct |
14 |
Correct |
10 ms |
33632 KB |
Output is correct |
15 |
Correct |
10 ms |
33624 KB |
Output is correct |
16 |
Correct |
10 ms |
31580 KB |
Output is correct |
17 |
Correct |
9 ms |
31580 KB |
Output is correct |
18 |
Correct |
10 ms |
31580 KB |
Output is correct |
19 |
Correct |
1205 ms |
121040 KB |
Output is correct |
20 |
Correct |
1237 ms |
129404 KB |
Output is correct |
21 |
Correct |
1199 ms |
129064 KB |
Output is correct |
22 |
Correct |
1207 ms |
129768 KB |
Output is correct |
23 |
Correct |
999 ms |
113388 KB |
Output is correct |
24 |
Correct |
89 ms |
40896 KB |
Output is correct |
25 |
Correct |
76 ms |
40928 KB |
Output is correct |
26 |
Correct |
66 ms |
36880 KB |
Output is correct |
27 |
Correct |
67 ms |
36684 KB |
Output is correct |
28 |
Correct |
69 ms |
36688 KB |
Output is correct |
29 |
Correct |
56 ms |
40788 KB |
Output is correct |
30 |
Correct |
56 ms |
40704 KB |
Output is correct |
31 |
Correct |
63 ms |
36080 KB |
Output is correct |
32 |
Correct |
34 ms |
33796 KB |
Output is correct |
33 |
Correct |
65 ms |
36604 KB |
Output is correct |
34 |
Correct |
197 ms |
52560 KB |
Output is correct |
35 |
Correct |
180 ms |
52620 KB |
Output is correct |
36 |
Correct |
171 ms |
53304 KB |
Output is correct |
37 |
Correct |
164 ms |
52876 KB |
Output is correct |
38 |
Correct |
161 ms |
52852 KB |
Output is correct |
39 |
Correct |
131 ms |
46760 KB |
Output is correct |
40 |
Correct |
126 ms |
46676 KB |
Output is correct |
41 |
Correct |
146 ms |
46484 KB |
Output is correct |
42 |
Correct |
140 ms |
46672 KB |
Output is correct |
43 |
Correct |
143 ms |
46576 KB |
Output is correct |
44 |
Correct |
149 ms |
46404 KB |
Output is correct |
45 |
Correct |
151 ms |
46640 KB |
Output is correct |
46 |
Correct |
166 ms |
46548 KB |
Output is correct |
47 |
Correct |
150 ms |
46340 KB |
Output is correct |
48 |
Correct |
149 ms |
46332 KB |
Output is correct |
49 |
Correct |
116 ms |
50112 KB |
Output is correct |
50 |
Correct |
117 ms |
50148 KB |
Output is correct |
51 |
Correct |
116 ms |
50180 KB |
Output is correct |
52 |
Correct |
117 ms |
50240 KB |
Output is correct |
53 |
Correct |
124 ms |
50464 KB |
Output is correct |
54 |
Correct |
151 ms |
46084 KB |
Output is correct |
55 |
Correct |
103 ms |
42156 KB |
Output is correct |
56 |
Correct |
139 ms |
45268 KB |
Output is correct |
57 |
Correct |
1210 ms |
128224 KB |
Output is correct |
58 |
Correct |
1182 ms |
128340 KB |
Output is correct |
59 |
Correct |
1088 ms |
129224 KB |
Output is correct |
60 |
Correct |
1129 ms |
129180 KB |
Output is correct |
61 |
Correct |
1085 ms |
129488 KB |
Output is correct |
62 |
Correct |
1071 ms |
129308 KB |
Output is correct |
63 |
Correct |
706 ms |
113712 KB |
Output is correct |
64 |
Correct |
694 ms |
113488 KB |
Output is correct |
65 |
Correct |
871 ms |
113060 KB |
Output is correct |
66 |
Correct |
921 ms |
112988 KB |
Output is correct |
67 |
Correct |
877 ms |
112976 KB |
Output is correct |
68 |
Correct |
920 ms |
112108 KB |
Output is correct |
69 |
Correct |
926 ms |
112236 KB |
Output is correct |
70 |
Correct |
949 ms |
112308 KB |
Output is correct |
71 |
Correct |
902 ms |
112212 KB |
Output is correct |
72 |
Correct |
921 ms |
112208 KB |
Output is correct |
73 |
Correct |
625 ms |
113684 KB |
Output is correct |
74 |
Correct |
600 ms |
114500 KB |
Output is correct |
75 |
Correct |
579 ms |
113492 KB |
Output is correct |
76 |
Correct |
582 ms |
113948 KB |
Output is correct |
77 |
Correct |
579 ms |
109900 KB |
Output is correct |
78 |
Correct |
862 ms |
107252 KB |
Output is correct |
79 |
Correct |
573 ms |
88844 KB |
Output is correct |
80 |
Correct |
789 ms |
99836 KB |
Output is correct |