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 ll long long
#define ar array
const int mxN=1e6;
int n, m, w[mxN], st[1<<21];
vector<ar<int, 3>> queries[mxN];
bool ans[mxN];
void upd(int i, int x, int u=1, int l=0, int r=n-1) {
if (l==r) {
st[u]=x;
return;
}
int mid=(l+r)/2;
i<=mid?upd(i, x, 2*u, l, mid):upd(i, x, 2*u+1, mid+1, r);
st[u]=max(st[2*u], st[2*u+1]);
}
int qry(int ql, int qr, int u=1, int l=0, int r=n-1) {
if (l>qr||r<ql)
return 0;
if (ql<=l&&r<=qr)
return st[u];
int mid=(l+r)/2;
return max(qry(ql, qr, 2*u, l, mid), qry(ql, qr, 2*u+1, mid+1, r));
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i=0; i<n; ++i)
cin >> w[i];
for (int i=0; i<m; ++i) {
int l, r, k;
cin >> l >> r >> k, --l, --r;
queries[r].push_back({l, k, i});
}
vector<int> st;
for (int i=0; i<n; ++i) {
while(st.size()&&w[i]>=w[st.back()])
st.pop_back();
if (st.size())
upd(st.back(), w[i]+w[st.back()]);
for (auto [l, k, ind] : queries[i])
ans[ind]=qry(l, i)<=k;
st.push_back(i);
}
for (int i=0; i<m; ++i)
cout << ans[i] << "\n";
return 0;
}
# | 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... |