#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 5001;
int a[N], pref[N];
int ans[N][N];
int main(){
int n, q;
cin >> n >> q;
a[0]=1e9+7;
for(int i=1; i<=n; i++){
cin>>a[i];
}
for(int i=1; i<=n; i++) {
pref[i]=i-1;
while(a[i]>=a[pref[i]]) {
pref[i]=pref[pref[i]];
}
}
for(int i=1; i<=n; i++){
ans[i][i]=0;
for(int j=i+1; j<=n; j++){
ans[i][j]=ans[i][j-1];
if(pref[j]>=i){
ans[i][j]=max(ans[i][j], a[pref[j]] + a[j]);
}
}
}
while(q--){
int l, r, k;
cin >> l >> r >> k;
if(ans[l][r]<=k){
cout<<"1\n";
}
else{
cout<<"0\n";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
3 ms |
10840 KB |
Output is correct |
7 |
Correct |
3 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
2 ms |
6488 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
3 ms |
10840 KB |
Output is correct |
7 |
Correct |
3 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
2 ms |
6488 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
13 ms |
29272 KB |
Output is correct |
12 |
Correct |
57 ms |
97072 KB |
Output is correct |
13 |
Correct |
47 ms |
97164 KB |
Output is correct |
14 |
Correct |
51 ms |
97360 KB |
Output is correct |
15 |
Correct |
51 ms |
97360 KB |
Output is correct |
16 |
Correct |
48 ms |
97364 KB |
Output is correct |
17 |
Correct |
36 ms |
80720 KB |
Output is correct |
18 |
Correct |
49 ms |
97364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
3 ms |
10840 KB |
Output is correct |
7 |
Correct |
3 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
2 ms |
6488 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
13 ms |
29272 KB |
Output is correct |
12 |
Correct |
57 ms |
97072 KB |
Output is correct |
13 |
Correct |
47 ms |
97164 KB |
Output is correct |
14 |
Correct |
51 ms |
97360 KB |
Output is correct |
15 |
Correct |
51 ms |
97360 KB |
Output is correct |
16 |
Correct |
48 ms |
97364 KB |
Output is correct |
17 |
Correct |
36 ms |
80720 KB |
Output is correct |
18 |
Correct |
49 ms |
97364 KB |
Output is correct |
19 |
Runtime error |
4 ms |
604 KB |
Execution killed with signal 11 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
3 ms |
10840 KB |
Output is correct |
7 |
Correct |
3 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
2 ms |
6488 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
13 ms |
29272 KB |
Output is correct |
12 |
Correct |
57 ms |
97072 KB |
Output is correct |
13 |
Correct |
47 ms |
97164 KB |
Output is correct |
14 |
Correct |
51 ms |
97360 KB |
Output is correct |
15 |
Correct |
51 ms |
97360 KB |
Output is correct |
16 |
Correct |
48 ms |
97364 KB |
Output is correct |
17 |
Correct |
36 ms |
80720 KB |
Output is correct |
18 |
Correct |
49 ms |
97364 KB |
Output is correct |
19 |
Runtime error |
4 ms |
600 KB |
Execution killed with signal 11 |
20 |
Halted |
0 ms |
0 KB |
- |