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
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;
struct query
{
int i, T, L, R;
};
ll N, Q, arr[200005], ans[200005];
query q[200005];
signed main()
{
cin >> N >> Q;
for (int i = 1; i <= N; i++)
cin >> arr[i];
for (int i = 1; i <= Q; i++)
{
cin >> q[i].T >> q[i].L >> q[i].R;
q[i].i = i;
}
sort(q + 1, q + 1 + Q, [](query q1, query q2)
{ return q1.L < q2.L; });
int qdx = 1;
vector<pll> v;
for (int i = 1; i <= N; i++)
{
while(!v.empty() && v.back().S <= arr[i])
v.pop_back();
v.push_back(pll{i, arr[i]});
while (qdx <= Q && q[qdx].L == i)
{
ans[q[qdx].i] = lower_bound(v.begin(), v.end(), pll{i - q[qdx].T, 0})->S;
qdx++;
}
}
for (int i = 1; i <= Q; 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... |