# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
689800 | nguyentunglam | Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) | C++17 | 833 ms | 94116 KiB |
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 fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 1e6 + 10;
int a[N], k[N], bit[N], ans[N];
int n, m;
vector<pair<int, int> > query[N];
void up(int pos, int val) {
while (pos) {
bit[pos] = max(bit[pos], val);
pos -= pos & -pos;
}
}
int get(int pos) {
int ret = 0;
while (pos <= n) {
ret = max(ret, bit[pos]);
pos += pos & -pos;
}
return ret;
}
int main() {
#define task ""
cin.tie(0) -> sync_with_stdio(0);
if (fopen ("task.inp", "r")) {
freopen ("task.inp", "r", stdin);
freopen ("task.out", "w", stdout);
}
if (fopen (task".inp", "r")) {
freopen (task".inp", "r", stdin);
freopen (task".out", "w", stdout);
}
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= m; i++) {
int l, r; cin >> l >> r >> k[i];
query[r].push_back({l, i});
}
stack<int> st;
for(int i = 1; i <= n; i++) {
while (!st.empty() && a[st.top()] <= a[i]) st.pop();
if (!st.empty()) up(st.top(), a[st.top()] + a[i]);
st.push(i);
for(auto [l, id] : query[i]) ans[id] = get(l);
}
for(int i = 1; i <= m; i++) cout << (ans[i] <= k[i]) << endl;
}
Compilation message (stderr)
# | 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... |