이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fs first
#define sc second
#define pb push_back
const int maxn=1e6;
int seg[4*maxn],lzy[4*maxn];
void prop(int v){
seg[2*v+1]=max(seg[2*v+1],lzy[v]);
seg[2*v+2]=max(seg[2*v+2],lzy[v]);
lzy[2*v+1]=max(lzy[2*v+1],lzy[v]);
lzy[2*v+2]=max(lzy[2*v+2],lzy[v]);
}
int upd(int v,int l,int r,int l2,int r2,int x){
if(l>r2||r<l2)return 0;
if(l2<=l&&r<=r2){
lzy[v]=max(lzy[v],x);
return seg[v]=max(seg[v],x);
}
prop(v);
int m=(l+r)/2;
return seg[v]=max(upd(2*v+1,l,m,l2,r2,x),upd(2*v+2,m+1,r,l2,r2,x));
}
int query(int v,int l,int r,int idx){
if(idx<l||idx>r)return 0;
if(l==r)return seg[v];
prop(v);
int m=(l+r)/2;
return max(query(2*v+1,l,m,idx),query(2*v+2,m+1,r,idx));
}
void solve() {
int n,q;
cin>>n>>q;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
bool ans[q];
vector<pair<pii,int>> qry[n];
for(int i=0;i<q;i++){
int l,r,k;
cin>>l>>r>>k;
qry[--r].pb({{--l,k},i});
}
vector<int> st;
for(int i=0;i<n;i++){
while(!st.empty()&&a[st.back()]<=a[i])st.pop_back();
if(!st.empty()){
int l,r=st.back();
if(st.size()>1)l=st[st.size()-2];
else l=0;
upd(0,0,n-1,l,r,a[r]+a[i]);
}
st.pb(i);
for(auto[p,idx]:qry[i]){
auto[l,k]=p;
ans[idx]=query(0,0,n-1,l)<=k;
}
}
for(bool b:ans)cout<<b<<'\n';
}
int main() {
#ifdef FPO
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |