제출 #173051

#제출 시각아이디문제언어결과실행 시간메모리
173051emil_physmathHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
0 / 100
836 ms262144 KiB
#include <algorithm> #include <iostream> #include <vector> #include <string> #include <set> using namespace std; int a[1000000]; set<int> t[4000000]; int ans[4000000]; int Max(const set<int>& x) { if (x.empty()) cerr << "Max got empty set as argument."; return *x.rbegin(); } void Build(int v, int vl, int vr) { if (vl == vr) { ans[v] = 0; t[v].insert(a[vr]); return; } int m = vl + (vr - vl) / 2; Build(v * 2, vl, m); Build(v * 2 + 1, m + 1, vr); t[v].insert(t[v * 2].begin(), t[v * 2].end()); t[v].insert(t[v * 2 + 1].begin(), t[v * 2 + 1].end()); ans[v] = max(ans[v * 2], ans[v * 2 + 1]); auto smaller = t[v * 2 + 1].lower_bound(Max(t[v * 2])); if (smaller != t[v * 2 + 1].begin()) { --smaller; ans[v] = max(ans[v], Max(t[v * 2]) + *smaller); } } int Query(int v, int vl, int vr, int l, int r, int maxAtLeft = 0) { // cerr << "(" << l << ", " << r << ") / (" << vl << ", " << vr << ")\n"; if (vl == l && vr == r) { int res = ans[v]; auto small = t[v].lower_bound(maxAtLeft); if (small != t[v].begin()) { --small; res = max(res, maxAtLeft + *small); } return res; } int m = vl + (vr - vl) / 2; if (r <= m) return Query(v * 2, vl, m, l, r, maxAtLeft); else if (l > m) return Query(v * 2 + 1, m + 1, vr, l, r, maxAtLeft); int res = Query(v * 2, vl, m, l, m, maxAtLeft); res = max(res, Query(v * 2 + 1, m + 1, vr, m + 1, r, max(Max(t[v * 2]), maxAtLeft))); return res; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) cin >> a[i]; Build(1, 0, n - 1); while (m--) { int l, r, w; cin >> l >> r >> w; cout << (Query(1, 0, n - 1, l - 1, r - 1) <= w) << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...