-
Notifications
You must be signed in to change notification settings - Fork 566
Convoluted Intervals Editorial #5461
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
base: master
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
solutions/silver/usaco-1160.mdx
Outdated
### Optimization 2 | ||
|
||
We should probably take advantage of the fact that $M$ is relatively small. | ||
Instead of looping through all pairs of intervals $(i, j)$ in $\mathcal{O}(N^2)$ time, we can iterate over all distinct $(a_i, a_j)$ and $(b_i, b_j)$ pairs in $\mathcal{O}(M^2)$. |
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.
how is this different from the iteration in the naive solution
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.
because the naive solution iterates all pairs of intervals (N intervals), and the improved solution iterates all pairs of values in a and b, and 1 <= a_i, b_i <= M
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 yeah this should probably be explained a bit more in detail
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.
how is the explanation now
solutions/silver/usaco-1160.mdx
Outdated
public | ||
class IntervalConvolution { |
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.
weird formatting
solutions/silver/usaco-1160.mdx
Outdated
long[] a_freq = new long[m + 1]; | ||
long[] b_freq = new long[m + 1]; |
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.
java uses camelcase
for more information, see https://pre-commit.ci
solutions/silver/usaco-1160.mdx
Outdated
vector<int64_t> win_start(2 * M + 1), win_end(2 * M + 1); | ||
{ | ||
vector<int64_t> a_freq(M + 1); | ||
for (int i = 0; i < N; ++i) ++a_freq.at(ivals.at(i).first); |
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.
we use postincrement here over preincrement
also always use braces
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 i just copied benqs edi code idrk cpp
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.
lemme try tho
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, does the cpp code work now?
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 was fine as it was
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.
(also, the current version doesn't compile)
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.
fixed now
solutions/silver/usaco-1160.mdx
Outdated
### Optimization 2 | ||
|
||
We should probably take advantage of the fact that $M$ is relatively small. | ||
Instead of looping through all pairs of intervals $(i, j)$ in $\mathcal{O}(N^2)$ time, we can iterate over all distinct $(a_i, a_j)$ and $(b_i, b_j)$ pairs in $\mathcal{O}(M^2)$. |
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 yeah this should probably be explained a bit more in detail
for more information, see https://pre-commit.ci
Place an "x" in the corresponding checkbox if it is done or does not apply to this pull request.