-
Notifications
You must be signed in to change notification settings - Fork 496
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
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 still throws a compilation error on usaco's website.
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.
oh lol, then change it back
} | ||
}; | ||
|
||
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.
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 agree 👍
i would prefer a lambda function, but it's up to you
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.
why is this initialized here
cin >> cow_proficiency[i].first; | ||
cow_proficiency[i].second = i; | ||
} | ||
vector edges(n, vector<int>()), heavy_paths(n, vector<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.
make these vector declarations on separate lines
} | ||
vector edges(n, vector<int>()), heavy_paths(n, vector<int>()); | ||
|
||
vector<int> sizes(n, 0), heavy_index(n, -1), path_index(n, -1), depth(n, 0), |
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.
same thing w/ declaring stuff on deparate lines
also, vectors autofill to 0
} | ||
}; | ||
|
||
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.
i agree 👍
i would prefer a lambda function, but it's up to you
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
// BeginCodeSnip{Segment Tree} |
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.
if this is copy-paste from the module, you should add (from the module) in the code snip title
Place an "x" in the corresponding checkbox if it is done or does not apply to this pull request.