Submission #581423

#TimeUsernameProblemLanguageResultExecution timeMemory
581423islingrHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
1251 ms137376 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include "bits/stdc++.h" using namespace std; using ll = long long; using ld = long double; #define rep(i, a, b) for (auto i{a}; i < (b); ++i) #define per(i, a, b) for (auto i{b}; i-- > (a);) #define all(x) begin(x), end(x) #define rall(x) (x).rbegin(), (x).rend() #define sz(x) static_cast<int>((x).size()) template <class T> bool uin(T& a, const T& b) { return a > b ? a = b, true : false; } template <class T> bool uax(T& a, const T& b) { return a < b ? a = b, true : false; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); struct segment_tree { static constexpr int inf = 1e9; int n; vector<int> t; segment_tree() {} segment_tree(int n) : n{n}, t(2 * n, -inf) {} int query(int l, int r) { int res = -inf; for (l += n, r += n; l < r; l >>= 1, r >>= 1) { if (l & 1) res = max(res, t[l++]); if (r & 1) res = max(res, t[--r]); } return res; } void update(int p, int x) { for (t[p += n] = x; p >>= 1;) t[p] = max(t[p << 1], t[p << 1 | 1]); } }; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector<int> a(n); for (auto& x : a) cin >> x; vector<int> p(n); // p[i] = last (strictly) greater element than a[i] rep(i, 0, n) { p[i] = i - 1; while (p[i] >= 0 && a[i] >= a[p[i]]) p[i] = p[p[i]]; } segment_tree t(n); vector<vector<int>> g(n); rep(i, 0, n) { if (p[i] < 0) continue; t.update(i, a[i] + a[p[i]]); g[p[i]].push_back(i); } vector<vector<tuple<int, int, int>>> queries(n); rep(i, 0, m) { int l, r, k; cin >> l >> r >> k; queries[l - 1].emplace_back(r, k, i); } vector<bool> ans(m); rep(l, 0, n) { for (auto [r, k, i] : queries[l]) ans[i] = t.query(l, r) <= k; for (auto c : g[l]) t.update(c, 0); } rep(i, 0, m) 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...