Submission #153576

#TimeUsernameProblemLanguageResultExecution timeMemory
153576leathermanHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
100 / 100
1779 ms118936 KiB
#include <bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("-O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #define fi first #define se second #define p_b push_back #define pll pair<ll,ll> #define pii pair<int,int> #define m_p make_pair #define all(x) x.begin(),x.end() #define sset ordered_set #define sqr(x) (x)*(x) #define pw(x) (1ll << x) using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; const ll MAXN = 1123456; const ll N = 2e5; mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count()); template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> void vout(T s){cout << s << endl;exit(0);} ll ans[MAXN]; vector <ll> v[MAXN]; struct qry{ ll l, r, idx, k; }; bool cmp(qry a, qry b){ if(a.l > b.l)return 1; if(a.l < b.l)return 0; return (a.idx < b.idx); } ll t[4 * MAXN]; void upd(ll v,ll tl,ll tr,ll pos,ll val) { if(tl == tr) { t[v] = max(t[v], val); return; } ll tm = (tl + tr) / 2; if(pos <= tm) upd(2 * v, tl, tm, pos, val); else upd(2 * v + 1, tm + 1, tr, pos, val); t[v] = max(t[2 * v], t[2 * v + 1]); } ll get(ll v,ll tl,ll tr,ll l,ll r) { if(l > r) return 0; if(tl == l && tr == r) return t[v]; ll tm = (tl + tr) / 2; return max(get(2 * v, tl, tm, l, min(r, tm)), get(2 * v + 1, tm + 1, tr, max(l, tm + 1), r)); } int main(){ ios_base :: sync_with_stdio(0); cin.tie(0); ll n, m; cin >> n >> m; vector <ll> w(n + 1), le(n + 1); for(int i = 1; i <= n; i++)cin >> w[i]; vector<pair<ll, ll> > v1; v1.p_b({1e18, 0}); for(int i = 1; i <= n; i++) { ll x = w[i]; while(x >= v1.back().fi) v1.pop_back(); v[v1.back().se].p_b(i); v1.p_b({x, i}); } vector <qry> c(m); ll uk = n; for(int i = 0; i < m; i++){ cin >> c[i].l >> c[i].r >> c[i].k; c[i].idx = i; } sort(all(c), cmp); for(auto kek : c){ while(kek.l < uk){ for(auto j : v[uk - 1]){ upd(1, 1, n, j, w[uk - 1] + w[j]); } uk--; } ans[kek.idx] = (get(1, 1, n, kek.l, kek.r) <= kek.k); } for(int i = 0; i < m; i++)cout << ans[i] << "\n"; return 0; }
#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...