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
const int NMAX = (int)1e6 + 50;
vector<vector<int>>R[NMAX];
int N,M,A[NMAX],ans[NMAX],mx[NMAX * 4];
void make(int i,int v,int l,int r,int x) {
if (l == r) {
mx[x] = max(mx[x],v);
return;
}
int mid = (l + r) / 2;
if (i <= mid) make(i,v,l,mid,2 * x);
else make(i,v,mid + 1,r,2 * x + 1);
mx[x] = max(mx[2 * x],mx[2 * x + 1]);
}
int get_maxim(int a,int b,int l,int r,int x) {
if (a <= l && r <= b)
return mx[x];
if (r < a || b < l)
return 0;
int mid = (l + r) / 2;
return max(get_maxim(a,b,l,mid,2 * x),get_maxim(a,b,mid + 1,r,2 * x + 1));
}
void solve() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> M;
for (int i = 1; i <= N;++i)
cin >> A[i];
for (int i = 1; i <= M;++i) {
int l,r,k; cin >> l >> r >> k;
R[r].push_back({l,k,i});
}
A[N + 1] = (int)1e9 * 2;
stack<int>q;
q.push(N + 1);
for (int i = 1; i <= N;++i) {
while (A[i] >= A[q.top()])
q.pop();
make(q.top(),A[i] + A[q.top()],1,N,1);
for (auto q : R[i]) {
ans[q[2]] = get_maxim(q[0],i,1,N,1) <= q[1];
}
}
for (int i = 1; i <= M;++i) {
cout << ans[i] << '\n';
//cout << i << ' ';
}
}
main() {
solve();
}
Compilation message (stderr)
sortbooks.cpp:60:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
60 | 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... |