-
Notifications
You must be signed in to change notification settings - Fork 494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HLD solution for Promotion Counting(Platinum) #4886
base: master
Are you sure you want to change the base?
HLD solution for Promotion Counting(Platinum) #4886
Conversation
for more information, see https://pre-commit.ci
segtrees[i] = segTree((int)heavy_paths[i].size()); | ||
} | ||
|
||
sort(cow_proficiency.begin(), cow_proficiency.end(), greater<pair<int, int>>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sort(cow_proficiency.begin(), cow_proficiency.end(), greater())
also works btw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it works locally but throws a compile error on usaco
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
most guide code is written to be submitted in C++ 17 I'm pretty sure
cuz like, with C++ there's literally no disadvantage with going with a higher version (I'm pretty sure)
if ur curious why, it's cuz of class template argument deduction
Add Centroid Decomp/HLD Solution | ||
**Time Complexity:** $\mathcal{O}(N\log ^2N)$ | ||
|
||
Sort the nodes from largest to smallest value, do path updates from each node to the root. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i get what you mean but like, maybe make the wording a bit more specific
like: "Sort the nodes in descending order of proficiency. When adding in each node, we do a path update from the root to this node." (except be specific with what type of path update we do)
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
template <class T> class SumSegmentTree { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put this in a codesnip
} | ||
}; | ||
|
||
void dfs_hld(vector<vector<int>> &edges, vector<vector<int>> &heavy_paths, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok i personally find this to be kind of ugly, ngl
IMO there's two ways to clean it up
- make these global arrays (sans might make u change it tho lol)
- lambda dfs
I would say don't change it yet, but be aware that you might be asked to later.
depth[i] = depth[start] + 1; | ||
dfs_hld(edges, heavy_paths, depth, sizes, i); | ||
sizes[start] += sizes[i]; | ||
if (heavy_child == -1 || sizes[heavy_child] < sizes[i]) heavy_child = i; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just in general put braces around blocks of code even if it's one statement
int main() { | ||
freopen("promote.in", "r", stdin); | ||
freopen("promote.out", "w", stdout); | ||
int N, current_value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very, very, very minor but preferably use n
instead of N
} | ||
|
||
sort(cow_proficiency.begin(), cow_proficiency.end(), greater<pair<int, int>>()); | ||
for (auto &p : cow_proficiency) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider using a structured binding
e.g. for (auto &[thing_a, thing_b] : cow_proficiency)
or something
if (heavy_index[p.second] != -1) { | ||
ans[p.second] = | ||
segtrees[heavy_index[p.second]].range_sum(0, path_index[p.second] + 1); | ||
} else ans[p.second] = cur_ans[p.second]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
braces
Place an "x" in the corresponding checkbox if it is done or does not apply to this pull request.