Submission #980693

#TimeUsernameProblemLanguageResultExecution timeMemory
980693michifiedHoliday (IOI14_holiday)C++17
23 / 100
32 ms9684 KiB
#include <bits/stdc++.h> #define ll long long #define lid id * 2 + 1 #define rid id * 2 + 2 #define pll pair<ll, ll> #define mp make_pair #define pb push_back using namespace std; struct node_t { ll tot, oncnt; }; int n; vector<node_t> st; vector<pll> cor; vector<int> pos; void build(int id, int l, int r) { if (l == r) { st[id] = {cor[l].first, 0}; return; } int mid = (l + r) / 2; build(lid, l, mid); build(rid, mid + 1, r); } ll que(int id, int l, int r, int take) { if (take == 0) return 0; if (take >= st[id].oncnt) return st[id].tot; int mid = (l + r) / 2; if (take >= st[lid].oncnt) return st[lid].tot + que(rid, mid + 1, r, take - st[lid].oncnt); return que(lid, l, mid, take); } void turnon(int id, int l, int r, int tgt, ll tgtval) { if (l == r) { st[id].oncnt = 1; return; } int mid = (l + r) / 2; if (tgt <= mid) turnon(lid, l, mid, tgt, tgtval); else turnon(rid, mid + 1, r, tgt, tgtval); st[id].oncnt++; st[id].tot += tgtval; } pll findpos(int d) { int i, bestpos; ll best = -1, res; for (i = 0; i < min(d, n); i++) { turnon(0, 0, n - 1, pos[i], cor[pos[i]].first); res = que(0, 0, n - 1, d - i); if (res > best) { best = res; bestpos = i; } } return mp(best, bestpos); } ll findMaxAttraction(int N, int start, int d, int att[]) { if (start != 0) return -1; int i; n = N; st.resize(n * 4); pos.resize(n); for (i = 0; i < n; i++) cor.pb(mp(att[i], i)); sort(cor.rbegin(), cor.rend()); for (i = 0; i < n; i++) pos[cor[i].second] = i; build(0, 0, n - 1); return findpos(d).first; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...