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>
#define STIZE(x) fprintf(stderr, "STIZE%d\n", x);
#define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x);
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mid (l+r)/2
#define endl '\n'
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 100005
int N, M, a[MAXN], rez[MAXN], seg[8*MAXN];
stack<int> st;
vector<pii> p;
struct Query{
int l, r, k, idx;
}q[MAXN];
void update(int node, int l, int r, int idx, int val) {
if(l == r) {
seg[node] = max(seg[node], val);
return;
}
if(idx <= mid) update(2*node, l, mid, idx, val);
else update(2*node+1, mid+1, r, idx, val);
seg[node] = max(seg[2*node], seg[2*node+1]);
}
int query(int node, int l, int r, int L, int R) {
if(L <= l && r <= R) return seg[node];
int rez = 0;
if(L <= mid) rez = max(rez, query(2*node, l, mid, L, R));
if(R > mid) rez = max(rez, query(2*node+1, mid+1, r, L, R));
return rez;
}
bool cmp1(Query a, Query b) {
return a.l > b.l;
}
int main() {
ios::sync_with_stdio(false);cin.tie(0);
cin >> N >> M;
a[0] = INF+1;
st.push(0);
for(int i = 1; i <= N; i++) {
cin >> a[i];
while(!st.empty() && a[i] >= a[st.top()]) st.pop();
if (!st.empty())
p.pb({st.top(), i});
st.push(i);
}
for(int i = 1; i <= M; i++) {
cin >> q[i].l >> q[i].r >> q[i].k;
q[i].idx = i;
}
sort(q+1, q+1+M, cmp1);
sort(all(p));
int id = N-1;
for(int i = 1; i <= M; i++) {
int l = q[i].l, r = q[i].r, k = q[i].k, idx = q[i].idx;
while(id >= 0 && l <= p[id].fi) {
update(1, 1, N, p[id].se, a[p[id].fi]+a[p[id].se]);
id--;
}
rez[idx] = (query(1, 1, N, l, r) <= k);
}
for(int i = 1; i <= M; i++) cout << rez[i] << endl;
return 0;
}
Compilation message (stderr)
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:52:8: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
52 | if (!st.empty())
| ^~
sortbooks.cpp:54:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
54 | st.push(i);
| ^~
# | 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... |