// Muallif: Mansuraliyev Husanboy Murotali o'g'li >> NamPS
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const double PI=3.1415926535897932384626433832795;
// 0-9 >> 48-57; A-Z>>65-90 and a-z>>97-122 respectively;
const int N=1e6+1;
ll a[N]; //map<ll,ll> mp;
pair<ll,int> tree[N*2+1];
int n;
void build(int x,int l, int r){
if(l==r){
tree[x].first=a[l];
tree[x].second=l;return;
}
int m=(l+r)/2;
build(x*2,l,m); build(x*2+1,m+1,r);
if(tree[x*2].first>tree[x*2+1].first){
tree[x]=tree[x*2];
}else{
tree[x]=tree[x*2+1];
}
return;
}
pair<ll,int> get(int x, int l, int r, int ll, int rr){
if(ll>r||rr<l){
return {-1,-1};
}
if(l>=ll&&r<=rr){
return tree[x];
}
int m=(l+r)/2;
auto as=get(x*2,l,m,ll,rr);
auto bs=get(x*2+1,m+1,r,ll,rr);
if(as.first>bs.first){
return as;
}
return bs;
}
void solve(){
int l,r;ll k; cin>>l>>r>>k;
while(l<r){
pair<ll,int> ans=get(1,1,n,l,r);//cout<<ans.second<<"gh ";
if(ans.second!=r){
pair<ll,int> p=get(1,1,n,ans.second+1,r); //cout<<p.first<<" ";
if(p.first+ans.first>k){
cout<<"0\n"; return ;
}else{
cout<<"1\n";return;
}
}r--;
}
cout<<"1\n";
}
int main(){
int m; cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i];//,mp[a[i]]=i;
build(1,1,n);
/*for(int i=1;i<=2*n;i++){
cout<<i<<": "<<tree[i].first<<' '<<tree[i].second<<"\n";
}*/
while(m--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
2 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
2 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3089 ms |
41060 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
291 ms |
6724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
2 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
2 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |