This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pair<int, int> >
#define fi first
#define se second
int n,m,q;
stack<int>st;
struct node{
int s,e,m,val;
node *l, *r;
node(int _s, int _e){
s = _s, e = _e, m = (s + e)/2;
val = 0;
if(s != e)l = new node(s, m), r = new node(m+1, e);
}
void upd(int p, int v){
if(s == e)val = max(val, v);
else{
if(p <= m)l->upd(p, v);
else r->upd(p, v);
val = max(l->val, r->val);
}
}
int query(int a, int b){
if(s == a && e == b)return val;
else if(b <= m)return l->query(a, b);
else if(a > m)return r->query(a, b);
else return max(l->query(a, m), r->query(m+1, b));
}
}*root;
int A[1000005], ans[1000005];
vector<pii> Q[1000005];
void solve(){
cin >> n >> q;
for(int i=1;i<=n;i++)cin >> A[i];
for(int i=1;i<=q;i++){
int x,y,z;
cin >> x >> y >> z;
Q[y].push_back({x, {z, i}});
}
root = new node(1, n);
for(int i=1;i<=n;i++){
while(!st.empty() && A[st.top()] <= A[i])st.pop();
if(!st.empty()){
int x = st.top();
root->upd(x, A[st.top()] + A[i]);
}
for(auto j : Q[i]){
int x = j.fi, y = j.se.fi, z = j.se.se;
ans[z] = (root->query(x, i) <= y);
}
st.push(i);
}
for(int i=1;i<=q;i++)cout << ans[i] << "\n";
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
Compilation message (stderr)
sortbooks.cpp:59:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
59 | main(){
| ^~~~
# | 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... |