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 all(i) (i).begin(), (i).end()
using namespace std;
void Debug(bool _split) {}
template<typename T1, typename ...T2>
void Debug(bool _split, T1 i, T2 ...j) {
if (_split)
cerr << ", ";
cerr << i;
Debug(true, j...);
}
#define debug(args...) cerr << "Line(" << __LINE__ << ") : [" << #args << "] is [", Debug(false, args), cerr << "]" << endl
template<typename T1, typename T2>
ostream& operator << (ostream& i, pair<T1, T2> j) {
return i << '(' << j.first << ", " << j.second << ')';
}
typedef long long ll;
typedef pair<int, int> pi;
const int inf = 0x3f3f3f3f, lg = 20;
const ll mod = 1e9 + 7, INF = 0x3f3f3f3f3f3f3f3f;
signed main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
int a[n];
for (int &i : a)
cin >> i;
vector<int> qry[n];
int l[m], k[m], ans[m];
for (int i = 0, x; i < m; ++i)
cin >> l[i] >> x >> k[i], --l[i], qry[--x].push_back(i);
vector<int> stk;
int bit[n + 1]{};
auto modify = [&](int i, int d) {
i = n - 1 - i;
for (++i; i <= n; i += i & -i)
bit[i] = max(bit[i], d);
};
auto query = [&](int i) {
i = n - 1 - i;
int res = 0;
for (++i; i; i -= i & -i)
res = max(res, bit[i]);
return res;
};
for (int i = 0; i < n; ++i) {
while (!stk.empty() && a[stk.back()] <= a[i]) {
if (stk.size() > 1) {
int x = stk[stk.size() - 2], y = stk.back();
modify(x, a[x] + a[y]);
}
stk.pop_back();
}
stk.push_back(i);
for (int j : qry[i]) {
int x = lower_bound(all(stk), l[j]) - stk.begin();
int tmp = x >= stk.size() - 1 ? 0 : a[stk[x]] + a[stk[x + 1]];
tmp = max(tmp, query(l[j]));
if (tmp <= k[j])
ans[j] = 1;
else
ans[j] = 0;
}
}
for (int i : ans)
cout << i << '\n';
}
Compilation message (stderr)
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:59:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | int tmp = x >= stk.size() - 1 ? 0 : a[stk[x]] + a[stk[x + 1]];
| ~~^~~~~~~~~~~~~~~~~
# | 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... |