Submission #1123727

#TimeUsernameProblemLanguageResultExecution timeMemory
1123727math_rabbit_1028Tree (IOI24_tree)C++20
0 / 100
2096 ms21988 KiB
#include "tree.h" #include <queue> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; int n; int par[202020]; vector<int> child[202020]; ll w[202020]; void init(vector<int> P, vector<int> W) { n = (int)P.size(); for (int i = 0; i < n; i++) { par[i] = P[i]; child[par[i]].push_back(i); } for (int i = 0; i < n; i++) w[i] = W[i]; } pll range[202020]; ll res[202020]; ll minabs(ll l, ll r) { if (l <= 0 && r >= 0) return 0; if (r < 0) return r; if (l > 0) return l; } void update(int v, ll L, ll R) { ll mns = 0, mxs = 0; for (int u : child[v]) { mns += range[u].first; mxs += range[u].second; } for (int u : child[v]) { range[u].first = max(range[u].first, L - range[v].second + range[u].second - mxs); range[u].second = min(range[u].second, R - range[v].first + range[u].first - mns); } } long long query(int L, int R) { ll ans = 0; priority_queue<pll> pq; for (int i = 0; i < n; i++) { ll m = child[i].size(); range[i] = {L-m*R, R-m*L}; pq.push({w[i], i}); } while (!pq.empty()) { int v = pq.top().second; pq.pop(); res[v] = minabs(range[v].first, range[v].second); pll temp = {range[v].second - res[v], res[v] - range[v].first}; range[v] = {res[v], res[v]}; ans += w[v] * abs(res[v]); update(v, L, R); int p = par[v]; if (p < 0) continue; ll mns = 0, mxs = 0; for (auto u : child[p]) { mns += range[u].first; mxs += range[u].second; } range[p].first = max(range[p].first, L - mxs); range[p].second = min(range[p].second, R - mns); update(p, L, R); } return ans; }

Compilation message (stderr)

tree.cpp: In function 'll minabs(ll, ll)':
tree.cpp:28:1: warning: control reaches end of non-void function [-Wreturn-type]
   28 | }
      | ^
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...