#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define loop(i, s, e) for (ll i = s; i < e; ++i)
#define pll pair<ll, ll>
struct Seg {
vll seg;
ll sz = 1;
Seg(ll n) {
for (; sz < n; sz *= 2)
;
seg.resize(2 * sz, -1);
}
void update(ll i, ll v) {
i += sz;
seg[i] = v;
for (i /= 2; i > 0; i /= 2)
seg[i] = max(seg[i * 2], seg[i * 2 + 1]);
}
ll query(ll l, ll r) {
ll ans = 0;
l += sz, r += sz;
while (l <= r) {
if (l & 1)
ans = max(ans, seg[l++]);
if (!(r & 1))
ans = max(ans, seg[r--]);
l /= 2;
r /= 2;
}
return ans;
}
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
ll n, m;
cin >> n >> m;
vll w(n);
loop(i, 0, n) cin >> w[i];
vector<ll> prevGreater(n, -1);
vector<ll> st;
loop(i, 0, n) {
while (!st.empty() && w[st.back()] <= w[i])
st.pop_back();
prevGreater[i] = st.empty() ? -10 : st.back();
st.push_back(i);
}
Seg seg(1e6 + 1);
for (ll i = 0; i < n; ++i)
seg.update(i, prevGreater[i]);
while (m--) {
ll l, r, k;
cin >> l >> r >> k;
bool ans = 1;
l--, r--;
ll maxi = seg.query(l, r);
if (maxi >= l) {
ans = 0;
}
cout << ans << "\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... |