#include <bits/stdc++.h>
#define N 1000005
using namespace std;
int a[N];
int ans[N];
struct node{
int val = 0,maxi = 0;
};
struct SegTree{
vector<node> t;
int n;
int idx,k;
SegTree(int sz){
n = sz;
t.assign(4*n,{0,0});
build(1,1,n);
}
node merge(node a,node b){
node ret;
ret.val = max(ret.val,b.val);
ret.maxi = max(a.maxi,b.maxi);
return ret;
}
void build(int v,int tl,int tr){
if(tl == tr){
t[v].maxi = a[tl];
return;
}
int tm = (tl + tr)/2;
build(v*2,tl,tm);
build(v*2+1,tm+1,tr);
t[v] = merge(t[v*2],t[v*2+1]);
for(int i = tm+1;i<=tr;i++){
if(a[i] < t[v*2].maxi){
t[v].val = max(t[v].val,t[v*2].maxi + a[i]);
}
}
}
node get(int v,int tl,int tr,int l,int r){
if(tr < l || r < tl){
return {0,0};
}
if(l <= tl && tr <= r){
return t[v];
}
int tm = (tl + tr)/2;
node aa = get(v*2,tl,tm,l,r);
node b = get(v*2+1,tm+1,tr,l,r);
//events.push_back({idx,max(l,tm+1),min(r,tr),k + 1 - a.maxi,a.maxi});
for(int i = max(l,tm+1);i<=min(r,tr);i++){
if(a[i] < aa.maxi){
aa.val = max(aa.val,a[i] + aa.maxi);
}
}
return merge(aa,b);
}
node get(int l,int r,int id,int kk){
idx = id;
k = kk;
return get(1,1,n,l,r);
}
};
void solve(){
int n,m;
cin >> n >> m;
for(int i = 1;i<=n;i++){
cin >> a[i];
}
SegTree t(n);
for(int i = 1;i<=m;i++){
int l,r,k;
cin >> l >> r >> k;
ans[i] = t.get(l,r,i,k).val <= k;
}
for(int i = 1;i<=m;i++){
cout << ans[i] << '\n';
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t=1;
//cin>>t;
while(t--){
solve();
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
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 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
936 ms |
41484 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
71 ms |
4412 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 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
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 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |