#include <bits/stdc++.h>
using namespace std;
#define sz(s) (int)s.size()
#define ff first
#define ss second
#define ll long long
const int N = 1e6 + 5;
ll n, m, a[N], b[N*4], mmx;
vector <vector <ll>> st;
void bld(int nd, int l, int r){
if(l == r){
st[nd].push_back(a[l]);
return;
}
int md = (l + r) / 2;
bld(nd*2,l,md);
bld(nd*2+1,md+1,r);
st[nd].resize(sz(st[nd*2]) + sz(st[nd*2+1]));
merge(st[nd*2].begin(), st[nd*2].end(), st[nd*2+1].begin(), st[nd*2+1].end(), st[nd].begin());
ll mx = 0;
for(int i = l; i <= r; i++){
if(mx > a[i]) b[nd] = max(b[nd],mx+a[i]);
mx = max(mx,a[i]);
}
return;
}
ll fnd(int nd, int l, int r, int x, int y){
if(r < x or l > y) return 0;
if(l >= x and r <= y){
int t = lower_bound(st[nd].begin(), st[nd].end(), mmx) - st[nd].begin();
ll k = 0;
if(t != 0) k = (mmx + st[nd][t-1]);
// cout << l << ' ' << r << ' ' << mmx << ' ' << k << ' ' << b[nd] << '\n';
k = max(k,b[nd]);
mmx = max(mmx,st[nd].back());
return k;
}
int md = (l + r) / 2;
ll x1 = fnd(nd*2,l,md,x,y);
ll x2 = fnd(nd*2+1,md+1,r,x,y);
return max(x1,x2);
}
int main(){
ios::sync_with_stdio (false); cin.tie(nullptr);
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
st.resize(n*4);
bld(1,1,n);
for(int i = 1; i <= m; i++){
ll l, r, k;
cin >> l >> r >> k;
mmx = 0;
int x = fnd(1,1,n,l,r);
cout << (x > k ? 0 : 1) << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
860 KB |
Output is correct |
12 |
Correct |
3 ms |
1628 KB |
Output is correct |
13 |
Correct |
3 ms |
1836 KB |
Output is correct |
14 |
Correct |
5 ms |
1884 KB |
Output is correct |
15 |
Correct |
5 ms |
1792 KB |
Output is correct |
16 |
Correct |
4 ms |
1624 KB |
Output is correct |
17 |
Correct |
4 ms |
1372 KB |
Output is correct |
18 |
Correct |
5 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
292 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
162 ms |
31300 KB |
Output is correct |
2 |
Correct |
110 ms |
31120 KB |
Output is correct |
3 |
Correct |
137 ms |
30060 KB |
Output is correct |
4 |
Correct |
125 ms |
30284 KB |
Output is correct |
5 |
Correct |
107 ms |
30292 KB |
Output is correct |
6 |
Correct |
88 ms |
30032 KB |
Output is correct |
7 |
Correct |
86 ms |
29908 KB |
Output is correct |
8 |
Correct |
90 ms |
29828 KB |
Output is correct |
9 |
Correct |
24 ms |
2076 KB |
Output is correct |
10 |
Correct |
91 ms |
29968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
860 KB |
Output is correct |
12 |
Correct |
3 ms |
1628 KB |
Output is correct |
13 |
Correct |
3 ms |
1836 KB |
Output is correct |
14 |
Correct |
5 ms |
1884 KB |
Output is correct |
15 |
Correct |
5 ms |
1792 KB |
Output is correct |
16 |
Correct |
4 ms |
1624 KB |
Output is correct |
17 |
Correct |
4 ms |
1372 KB |
Output is correct |
18 |
Correct |
5 ms |
1628 KB |
Output is correct |
19 |
Correct |
352 ms |
66288 KB |
Output is correct |
20 |
Correct |
334 ms |
66112 KB |
Output is correct |
21 |
Correct |
291 ms |
66144 KB |
Output is correct |
22 |
Correct |
301 ms |
66104 KB |
Output is correct |
23 |
Correct |
287 ms |
66064 KB |
Output is correct |
24 |
Correct |
214 ms |
63828 KB |
Output is correct |
25 |
Correct |
293 ms |
63832 KB |
Output is correct |
26 |
Correct |
301 ms |
64084 KB |
Output is correct |
27 |
Correct |
306 ms |
63988 KB |
Output is correct |
28 |
Correct |
278 ms |
64084 KB |
Output is correct |
29 |
Correct |
328 ms |
64084 KB |
Output is correct |
30 |
Correct |
343 ms |
64268 KB |
Output is correct |
31 |
Correct |
311 ms |
64224 KB |
Output is correct |
32 |
Correct |
327 ms |
64080 KB |
Output is correct |
33 |
Correct |
284 ms |
64084 KB |
Output is correct |
34 |
Correct |
190 ms |
63824 KB |
Output is correct |
35 |
Correct |
198 ms |
64084 KB |
Output is correct |
36 |
Correct |
212 ms |
63572 KB |
Output is correct |
37 |
Correct |
206 ms |
63684 KB |
Output is correct |
38 |
Correct |
195 ms |
63736 KB |
Output is correct |
39 |
Correct |
251 ms |
63540 KB |
Output is correct |
40 |
Correct |
154 ms |
42064 KB |
Output is correct |
41 |
Correct |
226 ms |
62288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
860 KB |
Output is correct |
12 |
Correct |
3 ms |
1628 KB |
Output is correct |
13 |
Correct |
3 ms |
1836 KB |
Output is correct |
14 |
Correct |
5 ms |
1884 KB |
Output is correct |
15 |
Correct |
5 ms |
1792 KB |
Output is correct |
16 |
Correct |
4 ms |
1624 KB |
Output is correct |
17 |
Correct |
4 ms |
1372 KB |
Output is correct |
18 |
Correct |
5 ms |
1628 KB |
Output is correct |
19 |
Runtime error |
292 ms |
262144 KB |
Execution killed with signal 9 |
20 |
Halted |
0 ms |
0 KB |
- |