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 ll long long
using namespace std;
const int N = 1e6 + 5;
const int M = 1e6 + 6;
const int B = 450;
struct Query {
ll l, mood, id;
};
ll n, m, a[N], pos[N];
vector <Query> g[N];
ll ans[N];
ll t[N * 4];
void upd(int pos, ll val, int v = 1, int tl = 1, int tr = n) {
if (tl == tr) {
t[v] = max(t[v], val);
return;
}
int tm = (tl + tr) / 2;
if (pos <= tm) upd(pos, val, v + v, tl, tm);
else upd(pos, val, v + v + 1, tm + 1, tr);
t[v] = max(t[v + v], t[v + v + 1]);
}
ll get(int l, int r, int v = 1, int tl = 1, int tr = n) {
if (r < tl || tr < l) return 0;
if (l <= tl && tr <= r) return t[v];
int tm = (tl + tr) / 2;
return max(get(l, r, v + v, tl, tm), get(l, r, v + v + 1, tm + 1, tr));
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; ++ i) {
cin >> a[i];
}
stack <int> st;
for (int i = 1; i <= n; ++ i) {
while (st.size() && a[st.top()] <= a[i]) st.pop();
if (st.size() > 0) pos[i] = st.top();
else pos[i] = 0;
st.push(i);
}
for (int i = 1; i <= m; ++ i) {
int l, r, mood;
cin >> l >> r >> mood;
g[r].push_back({l, mood, i});
}
for (int i = 1; i <= n; ++ i) {
if (pos[i] > 0) upd(pos[i], a[pos[i]] + a[i]);
for (auto [l, mood, id] : g[i]) {
if (get(l, i) <= mood) ans[id] = 1;
else ans[id] = 0;
}
}
for (int i = 1; i <= m; ++ i) cout << ans[i] << "\n";
}
# | 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... |