#include <bits/stdc++.h>
using namespace std;
#define sz(s) (int)s.size()
#define ff first
#define ss second
#define ll long long
ll n, m;
int main(){
ios::sync_with_stdio (false); cin.tie(nullptr);
cin >> n >> m;
ll nq = sqrt(n), cnt = 0;
vector <ll> a(n+1), id(n+1), an(nq+10), mmx(nq+10);
vector <pair<ll,ll>> rn(n+1);
for(int i = 1; i <= n; i++){
cin >> a[i];
}
vector <ll> v[nq+10];
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;
v[cnt].push_back(a[j]);
}
sort(v[cnt].begin(), v[cnt].end());
mmx[cnt] = mx;
rn[cnt] = {i,min(i+nq-1,n)};
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]);
int t = lower_bound(v[ind].begin(), v[ind].end(), mx) - v[ind].begin();
if(t != 0) ans = max(ans,mx+v[ind][t-1]);
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 |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
716 KB |
Output is correct |
14 |
Correct |
4 ms |
604 KB |
Output is correct |
15 |
Correct |
6 ms |
604 KB |
Output is correct |
16 |
Correct |
6 ms |
856 KB |
Output is correct |
17 |
Correct |
4 ms |
672 KB |
Output is correct |
18 |
Correct |
5 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3019 ms |
50840 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
156 ms |
6740 KB |
Output is correct |
2 |
Correct |
387 ms |
6764 KB |
Output is correct |
3 |
Correct |
174 ms |
6692 KB |
Output is correct |
4 |
Correct |
140 ms |
6812 KB |
Output is correct |
5 |
Correct |
124 ms |
7032 KB |
Output is correct |
6 |
Correct |
296 ms |
6736 KB |
Output is correct |
7 |
Correct |
303 ms |
6736 KB |
Output is correct |
8 |
Correct |
245 ms |
6484 KB |
Output is correct |
9 |
Correct |
39 ms |
1976 KB |
Output is correct |
10 |
Correct |
224 ms |
6660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
716 KB |
Output is correct |
14 |
Correct |
4 ms |
604 KB |
Output is correct |
15 |
Correct |
6 ms |
604 KB |
Output is correct |
16 |
Correct |
6 ms |
856 KB |
Output is correct |
17 |
Correct |
4 ms |
672 KB |
Output is correct |
18 |
Correct |
5 ms |
604 KB |
Output is correct |
19 |
Correct |
407 ms |
15444 KB |
Output is correct |
20 |
Correct |
417 ms |
15444 KB |
Output is correct |
21 |
Correct |
994 ms |
15392 KB |
Output is correct |
22 |
Correct |
946 ms |
15284 KB |
Output is correct |
23 |
Correct |
914 ms |
15356 KB |
Output is correct |
24 |
Correct |
876 ms |
15056 KB |
Output is correct |
25 |
Correct |
921 ms |
15188 KB |
Output is correct |
26 |
Correct |
732 ms |
15300 KB |
Output is correct |
27 |
Correct |
707 ms |
15196 KB |
Output is correct |
28 |
Correct |
680 ms |
15440 KB |
Output is correct |
29 |
Correct |
339 ms |
15440 KB |
Output is correct |
30 |
Correct |
374 ms |
15440 KB |
Output is correct |
31 |
Correct |
365 ms |
15440 KB |
Output is correct |
32 |
Correct |
359 ms |
15408 KB |
Output is correct |
33 |
Correct |
357 ms |
15440 KB |
Output is correct |
34 |
Correct |
918 ms |
15068 KB |
Output is correct |
35 |
Correct |
931 ms |
14908 KB |
Output is correct |
36 |
Correct |
907 ms |
14928 KB |
Output is correct |
37 |
Correct |
1124 ms |
14792 KB |
Output is correct |
38 |
Correct |
971 ms |
14932 KB |
Output is correct |
39 |
Correct |
653 ms |
13908 KB |
Output is correct |
40 |
Correct |
543 ms |
10884 KB |
Output is correct |
41 |
Correct |
661 ms |
13648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
716 KB |
Output is correct |
14 |
Correct |
4 ms |
604 KB |
Output is correct |
15 |
Correct |
6 ms |
604 KB |
Output is correct |
16 |
Correct |
6 ms |
856 KB |
Output is correct |
17 |
Correct |
4 ms |
672 KB |
Output is correct |
18 |
Correct |
5 ms |
604 KB |
Output is correct |
19 |
Execution timed out |
3019 ms |
50840 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |