#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(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m;
for(int i = 0; i < n; i++){
int a;
cin>>a;
arr.pb(a);
}
bool s = true;
if(n <= 5100 && m <= 5100 && 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<<"\n";
else
cout<<1<<"\n";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 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 |
0 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 |
1 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 |
Correct |
4 ms |
340 KB |
Output is correct |
12 |
Correct |
4 ms |
340 KB |
Output is correct |
13 |
Correct |
4 ms |
340 KB |
Output is correct |
14 |
Correct |
7 ms |
340 KB |
Output is correct |
15 |
Correct |
7 ms |
340 KB |
Output is correct |
16 |
Correct |
16 ms |
340 KB |
Output is correct |
17 |
Correct |
15 ms |
340 KB |
Output is correct |
18 |
Correct |
13 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
599 ms |
10240 KB |
Output is correct |
2 |
Correct |
610 ms |
10144 KB |
Output is correct |
3 |
Correct |
608 ms |
10220 KB |
Output is correct |
4 |
Correct |
633 ms |
10132 KB |
Output is correct |
5 |
Correct |
329 ms |
6288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
50 ms |
1392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 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 |
Correct |
4 ms |
340 KB |
Output is correct |
12 |
Correct |
4 ms |
340 KB |
Output is correct |
13 |
Correct |
4 ms |
340 KB |
Output is correct |
14 |
Correct |
7 ms |
340 KB |
Output is correct |
15 |
Correct |
7 ms |
340 KB |
Output is correct |
16 |
Correct |
16 ms |
340 KB |
Output is correct |
17 |
Correct |
15 ms |
340 KB |
Output is correct |
18 |
Correct |
13 ms |
340 KB |
Output is correct |
19 |
Incorrect |
109 ms |
2300 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 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 |
Correct |
4 ms |
340 KB |
Output is correct |
12 |
Correct |
4 ms |
340 KB |
Output is correct |
13 |
Correct |
4 ms |
340 KB |
Output is correct |
14 |
Correct |
7 ms |
340 KB |
Output is correct |
15 |
Correct |
7 ms |
340 KB |
Output is correct |
16 |
Correct |
16 ms |
340 KB |
Output is correct |
17 |
Correct |
15 ms |
340 KB |
Output is correct |
18 |
Correct |
13 ms |
340 KB |
Output is correct |
19 |
Correct |
599 ms |
10240 KB |
Output is correct |
20 |
Correct |
610 ms |
10144 KB |
Output is correct |
21 |
Correct |
608 ms |
10220 KB |
Output is correct |
22 |
Correct |
633 ms |
10132 KB |
Output is correct |
23 |
Correct |
329 ms |
6288 KB |
Output is correct |
24 |
Incorrect |
50 ms |
1392 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |