#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, l[N], r[N], a[N], id[N], an[N], mmx[N];
pair <ll,ll> rn[N];
int main(){
ios::sync_with_stdio (false); cin.tie(nullptr);
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
ll nq = sqrt(n), cnt = 0;
vector <vector <ll>> b(nq+10, vector <ll> (n+10,0));
for(int i = 1; i <= n; i++){
cnt++;
ll mx = 0;
for(int j = i; j <= min(i+nq-1,n); j++){
if(mx > a[j]) an[cnt] = max(an[cnt],mx+a[j]);
mx = max(mx,a[j]);
id[j] = cnt;
}
mmx[cnt] = mx;
rn[cnt] = {i,min(i+nq-1,n)};
i = min(i+nq-1,n);
}
vector <ll> v;
for(int i = 1; i <= n; i++){
v.clear();
for(int j = i; j <= min(i+nq-1,n); j++){
v.push_back(a[j]);
}
sort(v.begin(), v.end());
ll ind = 0;
ll mx = 0;
for(int j = i-1; j >= 1; j--){
mx = max(mx,a[j]);
while(ind < sz(v)-1 and v[ind+1] < mx) ind++;
b[id[i]][j] = v[ind];
}
i = min(i+nq-1,n);
}
for(int i = 1; i <= m; i++){
ll l, r, k;
cin >> l >> r >> k;
ll mx = 0, ans = 0;
for(int j = l; j <= min(rn[id[l]].ss,r); j++){
if(a[j] < mx) ans = max(ans,a[j]+mx);
mx = max(mx,a[j]);
}
ll ind = id[l]+1;
while(ind < id[r]){
ans = max(ans,an[ind]);
if(b[ind][l] < mx and b[ind][l] != 0) ans = max(ans,mx+b[ind][l]);
mx = max(mx,mmx[ind]);
ind++;
}
if(id[l] != id[r]){
for(int j = rn[id[r]].ff; j <= r; j++){
if(a[j] < mx) ans = max(ans,mx+a[j]);
mx = max(mx,a[j]);
}
}
cout << (ans > k ? 0 : 1) << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
1116 KB |
Output is correct |
12 |
Correct |
4 ms |
3736 KB |
Output is correct |
13 |
Correct |
4 ms |
3676 KB |
Output is correct |
14 |
Correct |
7 ms |
3676 KB |
Output is correct |
15 |
Correct |
6 ms |
3900 KB |
Output is correct |
16 |
Correct |
5 ms |
3680 KB |
Output is correct |
17 |
Correct |
4 ms |
3032 KB |
Output is correct |
18 |
Correct |
6 ms |
3832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
165 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
278 ms |
260164 KB |
Output is correct |
2 |
Correct |
470 ms |
259908 KB |
Output is correct |
3 |
Correct |
378 ms |
259892 KB |
Output is correct |
4 |
Correct |
316 ms |
260000 KB |
Output is correct |
5 |
Correct |
299 ms |
259900 KB |
Output is correct |
6 |
Correct |
317 ms |
259900 KB |
Output is correct |
7 |
Correct |
315 ms |
259900 KB |
Output is correct |
8 |
Correct |
319 ms |
259880 KB |
Output is correct |
9 |
Correct |
23 ms |
2128 KB |
Output is correct |
10 |
Correct |
349 ms |
259864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
1116 KB |
Output is correct |
12 |
Correct |
4 ms |
3736 KB |
Output is correct |
13 |
Correct |
4 ms |
3676 KB |
Output is correct |
14 |
Correct |
7 ms |
3676 KB |
Output is correct |
15 |
Correct |
6 ms |
3900 KB |
Output is correct |
16 |
Correct |
5 ms |
3680 KB |
Output is correct |
17 |
Correct |
4 ms |
3032 KB |
Output is correct |
18 |
Correct |
6 ms |
3832 KB |
Output is correct |
19 |
Runtime error |
131 ms |
262144 KB |
Execution killed with signal 9 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
1116 KB |
Output is correct |
12 |
Correct |
4 ms |
3736 KB |
Output is correct |
13 |
Correct |
4 ms |
3676 KB |
Output is correct |
14 |
Correct |
7 ms |
3676 KB |
Output is correct |
15 |
Correct |
6 ms |
3900 KB |
Output is correct |
16 |
Correct |
5 ms |
3680 KB |
Output is correct |
17 |
Correct |
4 ms |
3032 KB |
Output is correct |
18 |
Correct |
6 ms |
3832 KB |
Output is correct |
19 |
Runtime error |
165 ms |
262144 KB |
Execution killed with signal 9 |
20 |
Halted |
0 ms |
0 KB |
- |