Submission #684473

#TimeUsernameProblemLanguageResultExecution timeMemory
684473Chal1shkanHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
1219 ms72772 KiB
# include <bits/stdc++.h> # define pb push_back # define ff first # define ss second # define nl "\n" # define sz(x) ((int)(x).size()) typedef long long ll; typedef unsigned long long ull; typedef long double ld; const ll maxn = 1e6 + 25; const ll inf = 1e18 + 0; const ll mod = 1e9 + 7; const ll dx[] = {-1, 1, 0, 0}; const ll dy[] = {0, 0, -1, 1}; using namespace std; struct query { int l, k, id; query (int x, int y, int z) { l = x; k = y; id = x; } }; vector <query> q[maxn]; int n, m, a[maxn]; int t[maxn * 4]; int ans[maxn]; void update (int pos, int x, int v = 1, int tl = 1, int tr = n) { if (tl == tr) { t[v] = x; return; } int tm = (tl + tr) >> 1; if (pos <= tm) update(pos, x, v * 2, tl, tm); else update(pos, x, v * 2 + 1, tm + 1, tr); t[v] = max(t[v * 2], t[v * 2 + 1]); } int get (int l, int r, int v = 1, int tl = 1, int tr = n) { if (tr < l || r < tl) return 0; if (l <= tl && tr <= r) return t[v]; int tm = (tl + tr) >> 1; return max(get(l, r, v * 2, tl, tm), get(l, r, v * 2 + 1, tm + 1, tr)); } void ma1n (/* SABR */) { cin >> n >> m; for (int i = 1; i <= n; ++i) { cin >> a[i]; } for (int i = 1; i <= m; ++i) { int l, r, k; cin >> l >> r >> k; q[r].pb({l, k, i}); } vector <int> v; for (int r = 1; r <= n; ++r) { while (!v.empty() && a[v.back()] <= a[r]) v.pop_back(); if (!v.empty()) { update(v.back(), a[r] + a[v.back()]); } for (query i : q[r]) { int l = i.l, k = i.k, id = i.id; if (get(l, r) <= k) ans[id] = 1; } v.pb(r); } for (int i = 1; i <= m; ++i) cout << ans[i] << nl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("file.in", "r", stdin); // freopen("file.out", "w", stdout); int ttt = 1; // cin >> ttt; for (int test = 1; test <= ttt; ++test) { // cout << "Case " << test << ":" << ' '; ma1n(); } 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...