Submission #1302690

#TimeUsernameProblemLanguageResultExecution timeMemory
1302690WeIlIaNHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++20
100 / 100
1421 ms112048 KiB
#include <bits/stdc++.h> using namespace std; #define MOD1 1000000007 #define MOD2 998244353 #define fir first #define sec second #define pushf push_front #define pushb push_back #define popf pop_front #define popb pop_back #define mp make_pair #define all(a) a.begin(), a.end() #define lbound(v, x) lower_bound(all(v), x) - v.begin() #define ubound(v, x) upper_bound(all(v), x) - v.begin() #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) #define FOR1(a) for (int _ = 0; _ < (a); ++_) #define FOR2(i, a) for (int i = 0; i < (a); ++i) #define FOR3(i, a, b) for (int i = (a); i < (b); ++i) #define RFOR1(a) for (int _ = (a)-1; _ >= 0; --_) #define RFOR2(i, a) for (int i = (a)-1; i >= 0; --i) #define RFOR3(i, a, b) for (int i = (b)-1; i >= (a); --i) #define overload3(a, b, c, d, ...) d // Always choose the fourth argument to call. Hence, which function to call is determined by the number of given arguments. #define REP(...) overload3(__VA_ARGS__, FOR3, FOR2, FOR1)(__VA_ARGS__) #define RREP(...) overload3(__VA_ARGS__, RFOR3, RFOR2, RFOR1)(__VA_ARGS__) typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef vector<bool> vb; typedef vector<char> vc; typedef vector<string> vs; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef vector<vb> vvb; typedef vector<vc> vvc; typedef vector<vpii> vvpii; typedef vector<vpll> vvpll; typedef queue<int> qi; typedef queue<ll> qll; typedef queue<pii> qpii; typedef queue<pll> qpll; typedef deque<int> dqi; typedef deque<ll> dqll; typedef deque<pii> dqpii; typedef deque<pll> dqpll; typedef priority_queue<int> pqi; typedef priority_queue<ll> pqll; typedef priority_queue<pii> pqpii; typedef priority_queue<pll> pqpll; typedef priority_queue<int, vi, greater<int> > r_pqi; typedef priority_queue<ll, vll, greater<ll> > r_pqll; typedef priority_queue<pii, vpii, greater<pii> > r_pqpii; typedef priority_queue<pll, vpll, greater<pll> > r_pqpll; const ll inf = 1e9; struct node { int n; vll val, lazy; node(int size = 0) : n(size) { val.assign(4 * n, 0); lazy.assign(4 * n, 0); } void build(vll &arr, int ind = 1, int l = 0, int r = -1) { if(r == -1) r = n-1; if(l == r) { val[ind] = arr[l]; return; } int mid = (l + r) >> 1; build(arr, 2 * ind, l, mid); build(arr, 2 * ind + 1, mid + 1, r); val[ind] = val[2 * ind] + val[2 * ind + 1]; } void update(int q, ll v, int ind = 1, int l = 0, int r = -1) { if(r == -1) r = n-1; if(q > r || l > q) return; if(q <= l && r <= q) { val[ind] = v; return; } int mid = (l + r) / 2; update(q, v, 2 * ind, l, mid); update(q, v, 2 * ind + 1, mid + 1, r); val[ind] = max(val[2 * ind], val[2 * ind + 1]); } ll query(int ql, int qr, int ind = 1, int l = 0, int r = -1) { if(r == -1) r = n-1; if(ql > r || l > qr) return 0; if(ql <= l && r <= qr) return val[ind]; int mid = (l + r) / 2; return max(query(ql, qr, 2 * ind, l, mid), query(ql, qr, 2 * ind + 1, mid + 1, r)); } }; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin>>n>>m; vll arr(n+1); REP(i, 1, n+1) { cin>>arr[i]; } vector<array<int, 4>> qry(m); REP(i, m) { cin>>qry[i][0]>>qry[i][1]>>qry[i][2]; qry[i][3] = i; } sort(all(qry), [](array<int, 4>& a, array<int, 4>& b) { return a[1] < b[1]; }); vpll st; vpll val(n+1); REP(i, 1, n+1) { while(!st.empty() && st.back().fir <= arr[i]) { st.popb(); } val[i] = (st.empty() ? mp(0ll, 0ll) : mp(st.back().fir + arr[i], st.back().sec)); st.pushb(mp(arr[i], i)); } int r = 0; node root(n+1); vll ans(m); REP(i, m) { while(r < qry[i][1]) { r++; root.update(val[r].sec, val[r].fir); } ans[qry[i][3]] = (root.query(qry[i][0], qry[i][1]) <= qry[i][2]); } REP(i, m) { cout<<ans[i]<<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...