Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Vaishnav-K787
Copy link

Place an "x" in the corresponding checkbox if it is done or does not apply to this pull request.

  • I have tested my code.
  • I have added my solution according to the steps here.
  • I have followed the code conventions mentioned here.
    • I understand that if it is clear that I have not attempted to follow these conventions, my PR will be closed.
    • If changes are requested, I will re-request a review after addressing them.
  • I have linked this PR to any issues that it closes.

solutions/gold/usaco-696.mdx Outdated Show resolved Hide resolved
solutions/gold/usaco-696.mdx Outdated Show resolved Hide resolved
solutions/gold/usaco-696.mdx Outdated Show resolved Hide resolved
solutions/gold/usaco-696.mdx Outdated Show resolved Hide resolved
segtrees[i] = segTree((int)heavy_paths[i].size());
}

sort(cow_proficiency.begin(), cow_proficiency.end(), greater<pair<int, int>>());
Copy link
Contributor

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

Copy link
Author

@Vaishnav-K787 Vaishnav-K787 Nov 3, 2024

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

Copy link
Contributor

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

Copy link
Author

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.

Copy link
Contributor

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

solutions/gold/usaco-696.mdx Outdated Show resolved Hide resolved
solutions/gold/usaco-696.mdx Outdated Show resolved Hide resolved
solutions/gold/usaco-696.mdx Outdated Show resolved Hide resolved
solutions/gold/usaco-696.mdx Show resolved Hide resolved
}
};

void dfs_hld(vector<vector<int>> &edges, vector<vector<int>> &heavy_paths,
Copy link
Contributor

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

  1. make these global arrays (sans might make u change it tho lol)
  2. lambda dfs

I would say don't change it yet, but be aware that you might be asked to later.

Copy link
Member

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

solutions/gold/usaco-696.mdx Outdated Show resolved Hide resolved
solutions/gold/usaco-696.mdx Outdated Show resolved Hide resolved
solutions/gold/usaco-696.mdx Outdated Show resolved Hide resolved
solutions/gold/usaco-696.mdx Outdated Show resolved Hide resolved
int main() {
freopen("promote.in", "r", stdin);
freopen("promote.out", "w", stdout);
int n, current_value;
Copy link
Contributor

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>());
Copy link
Contributor

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),
Copy link
Contributor

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,
Copy link
Member

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}
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants