# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
333016 | Boaba | Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) | C++14 | 1231 ms | 109104 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 <cstdio>
#include <vector>
#define Max(a, b) (((a) < (b)) ? (b) : (a))
#pragma GCC optimize ("O3")
const int nmax = 1e6 + 5;
struct day {
int st, dr, ind, k;
};
int v[nmax], aib[nmax], n, m;
bool ans[nmax];
std::vector<int>st, last[nmax];
std::vector<day>skema[nmax];
void update(int poz, int val) {
for (; poz <= n; poz += poz & (-poz))
aib[poz] = Max(aib[poz], val);
}
int query(int poz) {
int ans = 0;
for (; poz > 0; poz -= poz & (-poz))
ans = Max(ans, aib[poz]);
return ans;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++){
scanf("%d", &v[i]);
while (!st.empty() and v[st.back()] <= v[i]) st.pop_back();
if (!st.empty()) last[st.back()].push_back(i);
st.push_back(i);
}
for (int i = 1; i <= m; i++) {
day aux;
scanf("%d %d %d", &aux.st, &aux.dr, &aux.k);
aux.ind = i;
skema[aux.st].push_back(aux);
}
for (int i = n; i > 0; i--) {
for (int x : last[i]) update(x, v[x] + v[i]);
for (day aux : skema[i]) ans[aux.ind] = (query(aux.dr) <= aux.k);
}
for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
return 0;
}
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... |