#include <bits/stdc++.h>
using namespace std;
#define int unsigned long long
#define ins insert
#define pb push_back
#define putr(x) cout<<x<<endl;return;
#define all(x) x.begin(),x.end()
#define endl '\n'
#define _ << " " <<
const int mod = 1e9+7,
sze = 1e6 +23*2,
inf = 1e9,
L = 23 ;
int T[sze+23];
void upd(int node,int v){
for(++node;node<=sze;node+=(node & -node)){
T[node]=max(T[node],v);
}
}
int qry(int node){
int mx=0;
for(++node;node>0; node -=(node & -node)){
mx=max(mx,T[node]);
}
return mx;
}
void _0x0(){
int n,q;
cin>>n>>q;
for(int i=0;i<=n+23;i++){
T[i]=0;
}
vector<int> arr(n);
vector<int> ans(q,0);
for(int i=0;i<n;i++){
cin>>arr[i];
}
vector< vector< pair< pair<int,int>, int> > > event(n+1);
int idx=0;
while(q--){
int l,r,k;
cin>>l>>r>>k;
--l;--r;
event[r].pb( { {l,k}, idx++} );
}
vector<int> lst;
for(int i=0;i<n;i++){
while(!lst.empty() && arr[lst.back()]<=arr[i]){
lst.pop_back();
}
if(!lst.empty()){
upd(lst.back(), arr[lst.back()] + arr[i]);
}
lst.pb(i);
for(auto v:event[i]){
if(qry(v.first.first)<=v.first.second){
ans[v.second]=1;
}
}
}
for(auto v:ans)cout<<v<<endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt = 1;
// cin>>tt;
while(tt--){
_0x0();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
428 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
428 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
599 ms |
113492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
35 ms |
10428 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
428 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
428 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |