Submission #658141

#TimeUsernameProblemLanguageResultExecution timeMemory
658141Danilo21Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
3067 ms261560 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define pb push_back #define fi first #define se second #define en '\n' #define sp ' ' #define tb '\t' #define ri(n) int n; cin >> n #define rl(n) ll n; cin >> n #define rs(s) string s; cin >> s #define rc(c) char c; cin >> c #define rv(v) for (auto &x : v) cin >> x #define pven(v) for (auto x : v) cout << x << en #define pv(v) for (auto x : v) cout << x << sp; cout << en #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define yes cout << "YES" << en #define no cout << "NO" << en #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) #define ssort(a, b) if (a < b) swap(a, b) #define bitcnt(a) (__builtin_popcountll(a)) #define bithigh(a) (63-__builtin_clzll(a)) #define lg bithigh #define highpow(a) (1LL << (ll)lg(a)) using namespace std; class segtree{ int n; vector<ll> tree; ll update(int s, int l, int r, int pos, ll x){ if (dbg) cout << l << sp << r << sp << pos << sp << x << en; if (l > pos || r < pos) return tree[s]; if (l == r) return tree[s] = x; int m = (l + r)>>1; ll a = update(2*s, l, m, pos, x); ll b = update(2*s+1, m+1, r, pos, x); return tree[s] = max(a, b); } ll query(int s, int l, int r, int ql, int qr) const { if (l > qr || r < ql) return 0; if (l >= ql && r <= qr) return tree[s]; int m = (l + r)>>1; ll a = query(2*s, l, m, ql, qr); ll b = query(2*s+1, m+1, r, ql, qr); return max(a, b); } public: bool dbg = 0; segtree(int n = 0){ Assign(n); } void Assign(int s){ n = highpow(s); if (bitcnt(s) > 1) n <<= 1; tree.assign(2*n, 0); } void update(int pos, ll x){ update(1, 0, n-1, pos, x); } ll query(int l, int r) const { return query(1, 0, n-1, l, r); } }; const ll LINF = 4e18; const int mxN = 1e6+10, INF = 2e9; ll n, m, a[mxN], f[mxN], ans[mxN]; array<ll, 4> q[mxN]; segtree st; void Solve(){ cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; stack<ll> stk; for (int i = 0; i < n; i++){ while (stk.size() && a[stk.top()] <= a[i]) stk.pop(); f[i] = (stk.size() ? stk.top() : -1); stk.push(i); } for (int i = 0; i < m; i++){ cin >> q[i][1] >> q[i][0] >> q[i][2]; q[i][0]--; q[i][1]--; q[i][3] = i; } sort(q, q+m); st.Assign(n); for (int i = 0, j = 0; j < m; j++){ auto [r, l, k, t] = q[j]; if (!l) st.dbg = 1; for (; i < n && i <= r; i++) if (~f[i]) st.update(f[i], a[i] + a[f[i]]); if (st.query(l, r) <= k) ans[t] = 1; } for (int i = 0; i < m; i++) cout << ans[i] << en; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0); cout << setprecision(12) << fixed; cerr << setprecision(12) << fixed; cerr << "Started!" << endl; int t = 1; //cin >> t; while (t--) Solve(); return 0; }

Compilation message (stderr)

sortbooks.cpp: In function 'void Solve()':
sortbooks.cpp:93:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   93 |         auto [r, l, k, t] = q[j];
      |              ^
#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...