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

Best Subsequence Editorial #5183

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

Conversation

TheGamingMousse
Copy link
Contributor

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.

ok hopefully adding this to monthlies works

It's always optimal to take the smallest suffix of $[l, r]$ that
has $K - X$ zeros. To intuitively understand this, consider the fact that
we want to maximize the first position where we have a zero in our subsequence. Given that we need to take at least $K-X$ zeros, we at a
minimum should take the last $K-X$ zeros in our range. Because we are
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are other ways to maximize the first zero position that don't take all of the last $K-X$ zeros


## Implementation

**Time Complexity:** $\mathcal{O}(Q\log^2N)$
Copy link
Member

@bqi343 bqi343 Mar 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+M(\log M + \log N) ?

Copy link
Member

@bqi343 bqi343 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some minor changes above


const int range_len = vals.size();
vector<int> diff(range_len);
for (const auto &[l, r] : upds) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think reference is required here

@Sosuke23
Copy link
Member

Sosuke23 commented Mar 9, 2025

Add some comments to the code.

@envyaims
Copy link
Member

u might want to add this to a module so ppl acc read this

@TheGamingMousse
Copy link
Contributor Author

u might want to add this to a module so ppl acc read this

what module would you recommend? im thinking hashing or additional practice (gold) would be suitable

@Sosuke23
Copy link
Member

u might want to add this to a module so ppl acc read this

what module would you recommend? im thinking hashing or additional practice (gold) would be suitable

Hashing is better

Co-authored-by: Benjamin Qi <bqi343@gmail.com>
@envyaims
Copy link
Member

what module would you recommend? im thinking hashing or additional practice (gold) would be suitable

coord compression or modular arith

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.

4 participants