#include <bits/stdc++.h>
using namespace std;
typedef int ll;
const ll Size=1e4+1;
class node{
public:
set<ll> nums;
ll ans;
};
ll w[Size];
node seg_tree[4*Size];
void build(ll l,ll r,ll i){
if(l==r){
seg_tree[i].ans=0;
seg_tree[i].nums.insert(w[l]);
}else{
ll mid=(l+r)/2;
build(l,mid,i*2);
build(mid+1,r,i*2+1);
ll max_v=*seg_tree[i*2].nums.rbegin(),largest_so_far=0;
for(auto itr:seg_tree[i*2+1].nums){
seg_tree[i].nums.insert(itr);
if(itr>=max_v)break;
largest_so_far=itr;
}
for(auto itr:seg_tree[i*2].nums){
seg_tree[i].nums.insert(itr);
}
if(!largest_so_far){
seg_tree[i].ans=max(seg_tree[i*2].ans,seg_tree[i*2+1].ans);
}else{
seg_tree[i].ans=max(max(seg_tree[i*2].ans,seg_tree[i*2+1].ans),max_v+largest_so_far);
}
}
}
node query(ll l,ll r,ll i,ll tl,ll tr){
if(l>tr or r<tl){
node a;
a.ans=-1;
return a;
}
if(l==r){
return seg_tree[i];
}else{
ll mid=(l+r)/2;
node n1=query(l,mid,i*2,tl,min(tr,mid));
node n2=query(mid+1,r,i*2+1,max(tl,mid+1),tr);
node res;
if(n1.ans==-1)return n2;
if(n2.ans==-1)return n1;
ll max_v=*n1.nums.rbegin(),largest_so_far=0;
for(auto itr:n2.nums){
res.nums.insert(itr);
if(itr>=max_v)break;
largest_so_far=itr;
}
for(auto itr:n1.nums){
res.nums.insert(itr);
}
if(!largest_so_far){
res.ans=max(n1.ans,n2.ans);
}else{
res.ans=max(max(n1.ans,n2.ans),max_v+largest_so_far);
}
return res;
}
}
void solve(){
ll n,m;
cin>>n>>m;
for(ll i=0;i<n;i++){
cin>>w[i];
}
build(0,n-1,1);
while(m--){
ll l,r,k;
cin>>l>>r>>k;
l--; r--;
node res=query(0,n-1,1,l,r);
cout<<(res.ans<=k)<<"\n";
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll t=1;
while(t--){
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2508 KB |
Output is correct |
2 |
Correct |
1 ms |
2380 KB |
Output is correct |
3 |
Incorrect |
8 ms |
2568 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2508 KB |
Output is correct |
2 |
Correct |
1 ms |
2380 KB |
Output is correct |
3 |
Incorrect |
8 ms |
2568 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
5172 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
5068 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2508 KB |
Output is correct |
2 |
Correct |
1 ms |
2380 KB |
Output is correct |
3 |
Incorrect |
8 ms |
2568 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2508 KB |
Output is correct |
2 |
Correct |
1 ms |
2380 KB |
Output is correct |
3 |
Incorrect |
8 ms |
2568 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |