Submission #171208

#TimeUsernameProblemLanguageResultExecution timeMemory
171208donentsetoHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
100 / 100
1223 ms89664 KiB
#include <bits/stdc++.h> using namespace std; int n, m, a [1000006]; struct query{ int l, k, idx; }; vector <query> v [1000006]; bool ans [1000006]; int bst [1000006]; void upd (int x, int val){ while (x <= n){ bst [x] = max (bst [x], val); x += x & -x; } } int q (int x){ int ans = 0; while (x > 0){ ans = max (ans, bst [x]); x -= x & -x; } return ans; } int main (){ ios::sync_with_stdio (false); cin.tie (0); cin >> n >> m; for (int i = 0; i < n; i ++) cin >> a [i]; for (int i = 0; i < m; i ++){ int l, r, k; cin >> l >> r >> k; v [r - 1].push_back ({l - 1, k, i}); } stack <pair <int, int> > s; for (int i = 0; i < n; i ++){ while (!s.empty () && s.top ().first <= a [i]) s.pop (); if (!s.empty ()) upd (n - s.top ().second, s.top ().first + a [i]); s.push ({a [i], i}); for (auto Q : v [i]){ if (q (n - Q.l) <= Q.k) ans [Q.idx] = 1; else ans [Q.idx] = 0; } } for (int i = 0; i < m; 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...