#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ar array
#define fr first
#define sc second
#define vec vector
#define ret return
#define ins insert
#define mk make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_back
#define int long long
#define pii pair<int,int>
#define all(s) s.begin(), s.end()
#define allr(s) s.rbegin(), s.rend()
#define NeedForSpeed ios::sync_with_stdio(0),cin.tie(0);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int N=1e6+12,INF=1e9,mod = 1e9+7;
bool iswowel(char n){ n = toupper(n); if(n == 'A' || n == 'O' || n == 'U' || n == 'E' || n == 'I') return true; else return false;}
int n,m,k,x,y,l,r,o,ans,res,ok,mx,mn = INF;
int a[N],t[N*4],b,c;
int get_max(int v,int l,int r,int ql,int qr){
if(r < ql || qr < l)
ret 0;
else if(l == r)
ret l;
int m = l + r >> 1;
if(t[v*2] >= t[v*2+1])
ret get_max(v*2,l,m,ql,qr);
else
ret get_max(v*2+1,m+1,r,ql,qr);
}
void build(int v, int l, int r){
if(l == r)
t[v] = a[l];
else{
int m = l + r >> 1;
build(v*2,l,m);
build(v*2+1,m+1,r);
t[v] = max(t[v*2], t[v*2+1]);
}
}
main(){
NeedForSpeed
cin>>n>>m;
for(int i=1; i<=n; i++){
cin>>a[i];
}
build(1,1,n);
while(m--){
cin>>l>>r>>k;
int x = get_max(1,1,n,l,r);
int s = get_max(1,1,n,x+1,r);
if(a[x] + a[s] <= k)cout << 1 << endl;
else cout<<0<<endl;
}
return 0;
}
Compilation message
sortbooks.cpp: In function 'long long int get_max(long long int, long long int, long long int, long long int, long long int)':
sortbooks.cpp:39:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
39 | int m = l + r >> 1;
| ~~^~~
sortbooks.cpp: In function 'void build(long long int, long long int, long long int)':
sortbooks.cpp:49:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
49 | int m = l + r >> 1;
| ~~^~~
sortbooks.cpp: At global scope:
sortbooks.cpp:56:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
56 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1625 ms |
26440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
161 ms |
3264 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |