#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define f first
#define s second
const int mxN = 1e6;
int n;
int vals[mxN];
int smax[4*mxN+1];
int ans[4*mxN+1];
vector<int> all[4*mxN+1];
void build(int l = 0, int r = n-1, int idx = 0){
if (l == r){
smax[idx] = vals[l];
ans[idx] = 0;
all[idx].pb(vals[l]);
return;
}
int m = (l+r)/2;
build(l,m,2*idx+1);
build(m+1,r,2*idx+2);
smax[idx] = max(smax[2*idx+1],smax[2*idx+2]);
ans[idx] = max(ans[2*idx+1],ans[2*idx+2]);
int cidx = lower_bound(all[2*idx+2].begin(),all[2*idx+2].end(),smax[2*idx+1]) - all[2*idx+2].begin();
if (cidx > 0) ans[idx] = max(ans[idx], smax[2*idx+1] + all[2*idx+2][cidx-1]);
cidx = 0;
for (int i = 0; i < m-l+1; i++){
while (cidx < r-m && all[2*idx+2][cidx] < all[2*idx+1][i]){
all[idx].pb(all[2*idx+2][cidx]);
cidx++;
}
all[idx].pb(all[2*idx+1][i]);
}
while (cidx < r-m){
all[idx].pb(all[2*idx+2][cidx]);
cidx++;
}
return;
}
pii query(int tl, int tr, int cmax = 0, int l = 0, int r = n-1, int idx = 0){
if (l > tr || r < tl) return {0,0};
if (l >= tl && r <= tr){
int cidx = lower_bound(all[idx].begin(),all[idx].end(),cmax) - all[idx].begin();
if (cidx > 0) return {max(ans[idx], all[idx][cidx-1] + cmax),smax[idx]};
return {ans[idx],smax[idx]};
}
int m = (l+r)/2;
pii v1 = query(tl,tr,cmax,l,m,2*idx+1);
pii v2 = query(tl,tr,max(cmax,v1.s),m+1,r,2*idx+2);
return {max(v1.f,v2.f), max(cmax,max(v1.s,v2.s))};
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int m;
cin >> n >> m;
for (int i =0; i < n; i++) cin >> vals[i];
build();
int l,r,k;
for (int i = 0; i < m; i++){
cin >> l >> r >> k;
l -= 1;
r -= 1;
pii res = query(l,r);
if (res.f <= k) cout << "1\n";
else cout << "0\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
98904 KB |
Output is correct |
2 |
Correct |
23 ms |
98900 KB |
Output is correct |
3 |
Correct |
24 ms |
99164 KB |
Output is correct |
4 |
Correct |
22 ms |
99032 KB |
Output is correct |
5 |
Correct |
22 ms |
99164 KB |
Output is correct |
6 |
Correct |
23 ms |
99356 KB |
Output is correct |
7 |
Correct |
22 ms |
99168 KB |
Output is correct |
8 |
Correct |
25 ms |
99164 KB |
Output is correct |
9 |
Correct |
23 ms |
99164 KB |
Output is correct |
10 |
Correct |
25 ms |
99160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
98904 KB |
Output is correct |
2 |
Correct |
23 ms |
98900 KB |
Output is correct |
3 |
Correct |
24 ms |
99164 KB |
Output is correct |
4 |
Correct |
22 ms |
99032 KB |
Output is correct |
5 |
Correct |
22 ms |
99164 KB |
Output is correct |
6 |
Correct |
23 ms |
99356 KB |
Output is correct |
7 |
Correct |
22 ms |
99168 KB |
Output is correct |
8 |
Correct |
25 ms |
99164 KB |
Output is correct |
9 |
Correct |
23 ms |
99164 KB |
Output is correct |
10 |
Correct |
25 ms |
99160 KB |
Output is correct |
11 |
Correct |
28 ms |
99140 KB |
Output is correct |
12 |
Correct |
28 ms |
99672 KB |
Output is correct |
13 |
Correct |
26 ms |
99676 KB |
Output is correct |
14 |
Correct |
28 ms |
99728 KB |
Output is correct |
15 |
Correct |
27 ms |
99932 KB |
Output is correct |
16 |
Correct |
27 ms |
99676 KB |
Output is correct |
17 |
Correct |
27 ms |
99664 KB |
Output is correct |
18 |
Correct |
27 ms |
99676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3058 ms |
262148 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
192 ms |
118620 KB |
Output is correct |
2 |
Correct |
154 ms |
118424 KB |
Output is correct |
3 |
Correct |
191 ms |
118612 KB |
Output is correct |
4 |
Correct |
152 ms |
118584 KB |
Output is correct |
5 |
Correct |
175 ms |
118560 KB |
Output is correct |
6 |
Correct |
114 ms |
118216 KB |
Output is correct |
7 |
Correct |
118 ms |
118340 KB |
Output is correct |
8 |
Correct |
133 ms |
118728 KB |
Output is correct |
9 |
Correct |
56 ms |
100444 KB |
Output is correct |
10 |
Correct |
142 ms |
118192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
98904 KB |
Output is correct |
2 |
Correct |
23 ms |
98900 KB |
Output is correct |
3 |
Correct |
24 ms |
99164 KB |
Output is correct |
4 |
Correct |
22 ms |
99032 KB |
Output is correct |
5 |
Correct |
22 ms |
99164 KB |
Output is correct |
6 |
Correct |
23 ms |
99356 KB |
Output is correct |
7 |
Correct |
22 ms |
99168 KB |
Output is correct |
8 |
Correct |
25 ms |
99164 KB |
Output is correct |
9 |
Correct |
23 ms |
99164 KB |
Output is correct |
10 |
Correct |
25 ms |
99160 KB |
Output is correct |
11 |
Correct |
28 ms |
99140 KB |
Output is correct |
12 |
Correct |
28 ms |
99672 KB |
Output is correct |
13 |
Correct |
26 ms |
99676 KB |
Output is correct |
14 |
Correct |
28 ms |
99728 KB |
Output is correct |
15 |
Correct |
27 ms |
99932 KB |
Output is correct |
16 |
Correct |
27 ms |
99676 KB |
Output is correct |
17 |
Correct |
27 ms |
99664 KB |
Output is correct |
18 |
Correct |
27 ms |
99676 KB |
Output is correct |
19 |
Correct |
481 ms |
139004 KB |
Output is correct |
20 |
Correct |
443 ms |
138860 KB |
Output is correct |
21 |
Correct |
366 ms |
138952 KB |
Output is correct |
22 |
Correct |
312 ms |
139204 KB |
Output is correct |
23 |
Correct |
342 ms |
139264 KB |
Output is correct |
24 |
Correct |
248 ms |
138976 KB |
Output is correct |
25 |
Correct |
318 ms |
139332 KB |
Output is correct |
26 |
Correct |
324 ms |
139188 KB |
Output is correct |
27 |
Correct |
347 ms |
139376 KB |
Output is correct |
28 |
Correct |
402 ms |
139152 KB |
Output is correct |
29 |
Correct |
380 ms |
139408 KB |
Output is correct |
30 |
Correct |
384 ms |
139348 KB |
Output is correct |
31 |
Correct |
383 ms |
139388 KB |
Output is correct |
32 |
Correct |
383 ms |
139464 KB |
Output is correct |
33 |
Correct |
449 ms |
139332 KB |
Output is correct |
34 |
Correct |
268 ms |
139092 KB |
Output is correct |
35 |
Correct |
233 ms |
138872 KB |
Output is correct |
36 |
Correct |
243 ms |
138952 KB |
Output is correct |
37 |
Correct |
240 ms |
138864 KB |
Output is correct |
38 |
Correct |
249 ms |
138956 KB |
Output is correct |
39 |
Correct |
339 ms |
138164 KB |
Output is correct |
40 |
Correct |
202 ms |
123552 KB |
Output is correct |
41 |
Correct |
308 ms |
137456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
98904 KB |
Output is correct |
2 |
Correct |
23 ms |
98900 KB |
Output is correct |
3 |
Correct |
24 ms |
99164 KB |
Output is correct |
4 |
Correct |
22 ms |
99032 KB |
Output is correct |
5 |
Correct |
22 ms |
99164 KB |
Output is correct |
6 |
Correct |
23 ms |
99356 KB |
Output is correct |
7 |
Correct |
22 ms |
99168 KB |
Output is correct |
8 |
Correct |
25 ms |
99164 KB |
Output is correct |
9 |
Correct |
23 ms |
99164 KB |
Output is correct |
10 |
Correct |
25 ms |
99160 KB |
Output is correct |
11 |
Correct |
28 ms |
99140 KB |
Output is correct |
12 |
Correct |
28 ms |
99672 KB |
Output is correct |
13 |
Correct |
26 ms |
99676 KB |
Output is correct |
14 |
Correct |
28 ms |
99728 KB |
Output is correct |
15 |
Correct |
27 ms |
99932 KB |
Output is correct |
16 |
Correct |
27 ms |
99676 KB |
Output is correct |
17 |
Correct |
27 ms |
99664 KB |
Output is correct |
18 |
Correct |
27 ms |
99676 KB |
Output is correct |
19 |
Execution timed out |
3058 ms |
262148 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |