제출 #685509

#제출 시각아이디문제언어결과실행 시간메모리
685509opPOHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
64 / 100
3050 ms245116 KiB
#pragma GCC optimize("O3,unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define f first #define s second #define pb push_back #define ld long double #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define vec vector using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using oset = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>; mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count()); const ld eps = 1e-6; const int mod = 1e9 + 7; const int oo = 2e9; const ll OO = 2e18; const int N = 1e6 + 10; int n, q, w[N], ans[4 * N]; vec<int> s[4 * N]; void merge(int v) { vec<int> &a = s[2 * v + 1], &b = s[2 * v + 2]; int n = sz(a), m = sz(b); int i = 0, j = 0; while (i < n || j < m) { if (i == n) s[v].pb(b[j++]); else if (j == m) s[v].pb(a[i++]); else { if (a[i] < b[j]) s[v].pb(a[i++]); else s[v].pb(b[j++]); } } ans[v] = max(ans[2 * v + 1], ans[2 * v + 2]); auto it = lower_bound(all(s[2 * v + 2]), s[2 * v + 1].back()); if (it != s[2 * v + 2].begin()) { --it; ans[v] = max(ans[v], s[2 * v + 1].back() + *it); } } void build(int v, int tl, int tr) { if (tl == tr) { s[v].pb(w[tl]); return; } int m = (tl + tr) / 2; build(2 * v + 1, tl, m); build(2 * v + 2, m + 1, tr); merge(v); } void get(vec<int> &p, int l, int r, int v, int tl, int tr) { if (tl > r || tr < l) return; if (tl >= l && tr <= r) { p.pb(v); return; } int m = (tl + tr) / 2; get(p, l, r, 2 * v + 1, tl, m); get(p, l, r, 2 * v + 2, m + 1, tr); } void solve() { cin >> n >> q; for (int i = 1; i <= n; i++) cin >> w[i]; build(0, 1, n); while (q--) { int l, r, k; cin >> l >> r >> k; vec<int> p; get(p, l, r, 0, 1, n); int mx = 0; for (int i = sz(p) - 1; i >= 0; i--) { mx = max(mx, ans[p[i]]); int val = 0; for (int j = 0; j < i; j++) val = max(val, s[p[j]].back()); auto it = lower_bound(all(s[p[i]]), val); if (it != s[p[i]].begin()) { --it; mx = max(mx, val + *it); } } if (mx <= k) cout << 1; else cout << 0; cout << "\n"; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); solve(); 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...