Submission #624341

#TimeUsernameProblemLanguageResultExecution timeMemory
624341dqhungdlHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
897 ms124136 KiB
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG #include "debug.hpp" #define debug(x...) cerr << "[" << #x << "] = [", _print(x) #else #define debug(x...) #endif #define int long long struct Query { int l, w, id; }; const int MAX = 1e6 + 5; int n, Q, a[MAX], L[MAX], rs[MAX], tree[MAX]; vector<Query> g[MAX]; void update(int idx, int val) { for (int i = idx; i; i -= i & -i) tree[i] = max(tree[i], val); } int query(int idx) { int rs = 0; for (int i = idx; i <= n; i += i & -i) rs = max(rs, tree[i]); return rs; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef DEBUG freopen("../_input", "r", stdin); #endif cin >> n >> Q; for (int i = 1; i <= n; i++) { cin >> a[i]; L[i] = i - 1; int tmp = i - 1; while (tmp && a[i] >= a[tmp]) L[i] = tmp = L[tmp]; } int l, r, w; for (int i = 1; i <= Q; i++) { cin >> l >> r >> w; g[r].push_back({l, w, i}); } for (int i = 1; i <= n; i++) { if (L[i]) update(L[i], a[L[i]] + a[i]); for (auto q: g[i]) rs[q.id] = query(q.l) <= q.w; } for (int i = 1; i <= Q; i++) cout << rs[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...