Submission #874371

#TimeUsernameProblemLanguageResultExecution timeMemory
874371MackerHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
0 / 100
2662 ms27056 KiB
#include <iostream> #include <vector> #include <list> #include <algorithm> #include <math.h> #include <tuple> #include <queue> #include <unordered_map> #include <unordered_set> #include <set> #include <map> #include <stack> #include <climits> #include <cassert> using namespace std; typedef long long ll; #define all(v) v.begin(), v.end() vector<int> st; int len = 1; int query(int f, int t, int i = 1, int s = 0, int e = len) { if (f >= e || t <= s) return { INT_MIN }; if (f <= s && e <= t) return st[i]; return max(query(f, t, i * 2, s, (s + e) / 2), query(f, t, i * 2 + 1, (s + e) / 2, e)); } void upd(int idx, int val, int i = 1, int s = 0, int e = len) { if (idx >= e || idx < s) return; if (idx == s && s + 1 == e) { st[i] = max(st[i], val); return; } upd(idx, val, i * 2, s, (s + e) / 2); upd(idx, val, i * 2 + 1, (s + e) / 2, e); st[i] = max(st[i * 2], st[i * 2 + 1]); } int main() { int n, q; cin >> n >> q; while (len < n) len *= 2; st.resize(2 * len, INT_MIN); stack<pair<int, int>> s; s.push({ INT_MAX, 0 }); for (int i = 0; i < n; i++) { int a; cin >> a; while (a >= s.top().first) s.pop(); upd(s.top().second, s.top().first + a); s.push({ a, i + 1 }); } while (q--) { int f, t, k; cin >> f >> t >> k; cout << (query(f, t + 1) <= k ? 1 : 0) << endl; } }
#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...