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 <vector>
#include <stack>
#include <algorithm>
using namespace std;
struct Query {
int l, r, w, ans;
};
int main() {
int n, k;
cin >> n >> k;
vector <int> v(n);
vector <Query> q(k);
for (int i = 0; i < n; i++)
cin >> v[i];
for (int i = 0; i < k; i++) {
cin >> q[i].l >> q[i].r >> q[i].w;
q[i].l--; q[i].r--;
}
vector <int> rightpos(n, -1);
stack <int> st;
for (int i = 0; i < n; i++) {
while (st.size() && v[i] > v[st.top()])
st.pop();
if (st.top())
rightpos[st.top()] = i;
st.push(i);
for (auto &qi : q) {
if (qi.r == i) {
qi.ans = 0;
for (int j = i; j >= qi.l; j--)
if (rightpos[j] != -1)
qi.ans = max(qi.ans, v[j] + v[rightpos[j]]);
}
}
}
for (auto qi : q) {
// cerr << qi.ans << '\n';
if (qi.ans > qi.w)
cout << 0 << '\n';
else cout << 1 << '\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... |