Submission #555658

#TimeUsernameProblemLanguageResultExecution timeMemory
555658fleimgruberHoliday (IOI14_holiday)C++17
23 / 100
21 ms5792 KiB
// still only subtask 2 #include "holiday.h" #include <bits/stdc++.h> using namespace std; struct SegmentTree { int n; struct Value { long long sum = 0; int size = 0; friend Value operator+(const Value& a, const Value& b) { return { a.sum + b.sum, a.size + b.size }; } }; vector<Value> tree; int round_up(int n) { while (n & (n-1)) n++; return n; } SegmentTree(int n_) : n(round_up(n_)), tree(2*n) { } void set(int i, const Value& value) { i += n; tree[i] = value; for (i /= 2; i > 0; i /= 2) tree[i] = tree[2*i] + tree[2*i+1]; } long long descend(int budget) { if (tree[1].size <= budget) return tree[1].sum; long long sum = 0; for (int i = 1; i < n;) if (tree[2*i].size > budget) i = 2*i; else { sum += tree[2*i].sum; budget -= tree[2*i].size; i = 2*i+1; } return sum; } }; long long findMaxAttraction(int n, int start, int d, int attraction[]) { vector<int> sorted(n), rank(n); iota(sorted.begin(), sorted.end(), 0); sort(sorted.begin(), sorted.end(), [&](int i, int j) { return attraction[i] > attraction[j]; }); for (int i = 0; i < n; i++) rank[sorted[i]] = i; SegmentTree tree(n); long long ans = 0; for (int r = 0; r < min(n, d); r++) { tree.set(rank[r], { attraction[r], 1 }); ans = max(ans, tree.descend(d - r)); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...