#include <bits/stdc++.h>
#define int long long
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file(s) freopen(s".in", "r", stdin); freopen(s".out", "w", stdout)
const int N=1e6+1;
const int inf=1e18;
const int mod=1e9+7;
using namespace std;
struct edge{
int l,k,id;
};
vector<edge>v1[N];
vector<int>v;
int t[4*N];
void upd(int n,int tl,int tr,int pos,int x){
if(tl==tr){
t[n]=x;
return;
}
int mid=(tl+tr)/2;
upd(n*2,tl,mid,pos,x);
upd(n*2+1,mid+1,tr,pos,x);
t[n]=max(t[n*2],t[n*2+1]);
}
int get(int n,int tl,int tr,int l,int r){
if(tr<l||r<tl){
return 0;
}
if(l<=tl&&tr<=r){
return t[n];
}
int mid=(tl+tr)/2;
return max(get(n*2,tl,mid,l,r),get(n*2+1,mid+1,tr,l,r));
}
stack<pair<int,int> >st;
int ans[N];
signed main(){
boost;
int n,m;
cin>>n>>m;
v.push_back(0);
for(int i=1;i<=n;i++){
int x;
cin>>x;
v.push_back(x);
}
for(int i=1;i<=m;i++){
int l,r,k;
cin>>l>>r>>k;
edge x;
x.l=l;
x.k=k;
x.id=i;
v1[r].push_back(x);
}
for(int i=1;i<=n;i++){
if(v1[i].size()>0){
while(st.top().first<v[i]&&st.size()>0){
st.pop();
}
if(st.size()>0){
upd(1,1,n,st.top().second,st.top().first+v[i]);
}
}
for(int j=0;j<v1[i].size();j++){
ans[v1[i][j].id]=(get(1,1,n,v1[i][j].l,i)<=v1[i][j].k);
}
st.push({v[i],i});
}
for(int i=1;i<=m;i++){
cout<<ans[i]<<"\n";
}
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:65:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int j=0;j<v1[i].size();j++){
| ~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
27996 KB |
Output is correct |
2 |
Runtime error |
23 ms |
56264 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
27996 KB |
Output is correct |
2 |
Runtime error |
23 ms |
56264 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3011 ms |
118196 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3067 ms |
38552 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
27996 KB |
Output is correct |
2 |
Runtime error |
23 ms |
56264 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
27996 KB |
Output is correct |
2 |
Runtime error |
23 ms |
56264 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |