Submission #874384

#TimeUsernameProblemLanguageResultExecution timeMemory
874384MackerHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
1160 ms102724 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() { ios_base::sync_with_stdio(0); cin.tie(0); int n, q; cin >> n >> q; vector<int> v(n); for (auto& i : v) { cin >> i; } while (len < n) len *= 2; st.resize(2 * len, INT_MIN); vector<bool> ans(q); vector<tuple<int, int, int>> qry; vector<vector<pair<int, int>>> ls(n+1); for (int i = 0; i < q; i++) { int f, t, k; cin >> f >> t >> k; qry.push_back({ f, t, k }); ls[t].push_back({ f, i }); } stack<pair<int, int>> s; s.push({ INT_MAX, 0 }); for (int i = 0; i < n; i++) { while (v[i] >= s.top().first) s.pop(); upd(s.top().second, s.top().first + v[i]); s.push({ v[i], i + 1}); for (auto& f : ls[i + 1]) { ans[f.second] = (query(f.first, len+1) <= get<2>(qry[f.second])); } } for (int i = 0; i < q; i++) { cout << ans[i] << '\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...