#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<long long> vl;
typedef vector<int> vi;
int n, m;
vi arr;
int main(){
cin>>n>>m;
for(int i = 0; i < n; i++){
int a;
cin>>a;
arr.pb(a);
}
bool s = true;
if(n <= 1000 && m <= 1000 && s){
while(m--){
int l, r, k;
cin>>l>>r>>k;
l--; r--;
bool can = true;
int maxi = -1e9;
for(int i = l; i <= r; i++){
if(maxi > arr[i] && maxi + arr[i] > k){
can = false;
break;
}
maxi = max(maxi, arr[i]);
}
cout<<can<<endl;
}
}
else{
vi pregrada;
for(int i = 0; i < n; i++){
int j =i;
pregrada.pb(i);
while(j + 1 < n && arr[j] <= arr[j+1]){
j++;
}
if(j == n-1) pregrada.pb(n);
i = j;
}
while(m--){
int l, r, k;
cin>>l>>r>>k;
l--;r--;
int left_border = -1, right_border = -1;
int levo = 0, desno = pregrada.size()-1;
while(levo <= desno){
int mid = (levo + desno) / 2;
if(pregrada[mid] <= l){
left_border = mid;
levo = mid + 1;
}
else
desno = mid - 1;
}
levo = 0; desno = pregrada.size()-1;
while(levo <= desno){
int mid = (levo + desno) / 2;
if(pregrada[mid] > r){
right_border = mid;
desno = mid - 1;
}
else
levo = mid + 1;
}
// cout<<left_border<<" "<<right_border<<endl;
if(abs(left_border - right_border) != 1)
cout<<0<<endl;
else
cout<<1<<endl;
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
2 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
2 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Incorrect |
6 ms |
212 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2320 ms |
10272 KB |
Output is correct |
2 |
Correct |
2341 ms |
10128 KB |
Output is correct |
3 |
Correct |
2331 ms |
10204 KB |
Output is correct |
4 |
Correct |
2344 ms |
10384 KB |
Output is correct |
5 |
Correct |
2040 ms |
29108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
192 ms |
1216 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
2 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Incorrect |
6 ms |
212 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
2 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Incorrect |
6 ms |
212 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |