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 <iostream>
#include <stack>
#include <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
using namespace std;
#define ALL(x) x.begin(), x.end()
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
using ll = long long;
#define N 1000005
int n, m, a[N], t[N<<1], d[N<<1], e[N];
array<int, 4> b[N];
void push(int v, int l, int r)
{
t[v] += d[v];
if (l ^ r)
{
int m = (l+r)/2, vl=v+1, vr=v+(m-l+1)*2;
d[vl] += d[v], d[vr] += d[v];
}
d[v] = 0;
}
void add(int x, int y, int k, int v, int l, int r)
{
push(v, l, r);
if (y < l || r < x) return;
if (x <= l && r <= y) { d[v] = k; push(v, l, r); return; }
int m = (l+r)/2, vl=v+1, vr=v+(m-l+1)*2;
add(x, y, k, vl, l, m);
add(x, y, k, vr, m+1, r);
t[v] = max(t[vl], t[vr]);
}
int query(int x, int y, int v, int l, int r)
{
push(v, l, r);
if (y < l || r < x) return 0;
if (x <= l && r <= y) return t[v];
int m = (l+r)/2, vl=v+1, vr=v+(m-l+1)*2;
return max(query(x, y, vl, l, m), query(x, y, vr, m+1, r));
}
std::stack<int> s;
int main()
{
ShinLena;
cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 0; i < m; ++i) cin >> b[i][0] >> b[i][1] >> b[i][2], b[i][3] = i;
sort(b, b+m);
s.push(n+1); a[n+1] = 2e9;
int j = m-1;
for (int i = n; i >= 1; --i)
{
while (s.size() && a[s.top()] <= a[i])
{
int x = s.top();
s.pop();
add(x+1, s.top() - 1, -a[x], 0, 1, n);
}
add(i+1, s.top() - 1, a[i], 0, 1, n);
s.push(i);
for (; j >= 0 && b[j][0] == i; --j) e[b[j][3]] = b[j][2] >= query(i+1, b[j][1], 0, 1, n);
add(i, i, a[i], 0, 1, n);
}
for (int i = 0; i < m; ++i) cout << e[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... |