제출 #980760

#제출 시각아이디문제언어결과실행 시간메모리
980760michified휴가 (IOI14_holiday)C++17
0 / 100
3800 ms1408 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, d; vector<node_t> st; vector<pll> cor, bestdpl, bestdpr, bestdplp1, bestdprp1; 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); } void dc(vector<pll>& res) { int i, j; for (i = 0; i <= d; i++) { res[i] = findpos(i); st.clear(); st.resize(n * 4); build(0, 0, n - 1); } } ll findMaxAttraction(int N, int start, int D, int att[]) { if (N > 3000) return -1; int i; d = D; bestdpl.resize(d + 1); bestdpr.resize(d + 1); bestdplp1.resize(d + 1); bestdprp1.resize(d + 1); n = N; st.resize(n * 4); pos.resize(n); for (i = start; i < n; i++) cor.pb(mp(att[i], i - start)); sort(cor.rbegin(), cor.rend()); n = cor.size(); for (i = 0; i < n; i++) pos[cor[i].second] = i; build(0, 0, n - 1); dc(bestdpr); if (start < n - 1) { n = N; st.clear(); st.resize(n * 4); pos.clear(); pos.resize(n); cor.clear(); for (i = start + 1; i < n; i++) cor.pb(mp(att[i], i - start - 1)); sort(cor.rbegin(), cor.rend()); n = cor.size(); for (i = 0; i < n; i++) pos[cor[i].second] = i; build(0, 0, n - 1); dc(bestdprp1); } n = N; st.clear(); st.resize(n * 4); pos.clear(); pos.resize(n); cor.clear(); for (i = start; i >= 0; i--) cor.pb(mp(att[i], start - i)); sort(cor.rbegin(), cor.rend()); n = cor.size(); for (i = start; i >= 0; i--) pos[cor[i].second] = start - i; build(0, 0, n - 1); dc(bestdpl); if (start > 0) { n = N; st.clear(); st.resize(n * 4); pos.clear(); pos.resize(n); cor.clear(); for (i = start - 1; i >= 0; i--) cor.pb(mp(att[i], start - i - 1)); sort(cor.rbegin(), cor.rend()); n = cor.size(); for (i = start - 1; i >= 0; i--) pos[cor[i].second] = start - i - 1; build(0, 0, n - 1); dc(bestdplp1); } ll ans = max(start > 0 ? bestdpl[d].first : 0, start < n - 1 ? bestdpr[d].first : 0); // rL if (start < n - 1) { for (i = 0; i < d; i++) ans = max(ans, bestdpr[i].first + bestdplp1[max(d - bestdpr[i].second - i - 1, 0ll)].first); } // lR if (start > 0) { for (i = 0; i < d; i++) ans = max(ans, bestdpl[i].first + bestdprp1[max(d - bestdpl[i].second - i - 1, 0ll)].first); } return ans; }

컴파일 시 표준 에러 (stderr) 메시지

holiday.cpp: In function 'void dc(std::vector<std::pair<long long int, long long int> >&)':
holiday.cpp:64:12: warning: unused variable 'j' [-Wunused-variable]
   64 |     int i, 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...