Open source contribution && cool problems
My PR was finally merged!

This is my first time contributing to open source, so it’s really exciting for me :D
The fix was for OpenMMlab’s MMsegmentation, which is a framework for AI segmentation tasks. We used it in our research im conducting now at Academia Sinica. I’ll write about it some day.
Anyways, we were met with the problem of not being able to combine dice loss with other losses correctly, and after searching, alot of other people had the same problem as well!
After some discussion, one of the maintainers asked if I want to do a PR to solve this problem.
Initially, I was very hesitant, as I had no experiences with contributing to open source. But I still tried my best and started my journey of contributing open source for the first time.
I actually learned alot during this experience! I learned about linting, coding formats, unit testing, pre-commit checks and more, something you wouldn’t really encounter if you only do small projects that doesn’t need to be maintained. Also, I was met with quite alot of problems! Luckly, people were really helpful and kind for solving all my newbie questions.
In conclusion, open source contributing is a new experience for me, and I think i’ll keep doing it in the future, as it really feels like you’re actually making the world better! :D
======
I also signed up for CF round 891(Div. 3), although registered as out of competition, I still tried my best!
My performance was extremely disappointing though. I only solved A ~ E, and got a ranking around 2k…
I was very defeated by my performance, as nearly 1.5k people solved pF, and as a expert ranked I couldn’t solve it.
The problems were all pretty solid and it was a decent round though, it was purely my problem.
The reason I was stuck for so long was due to me being too reluctant with my initial ideas.
The problem was for a query, find the number of pairs in the array such that , ,
I do not understand why I didn’t identify that it’s Vieta’s formula in an instant…
Instead, I reorganized the equations to and couldn’t find how this could be done quickly for an hour.
I should’ve chose to drop my idea and think again after maybe like 30 minutes, but I was too stubborn.
At least I learned a valueable lesson here and I hope to not make the same mistake from now on :D
After failing to solve basic math in contest, I decided to practice some math(related) questions:
CF 1804C. Pull Your Luck
I am fully ashamed how I can’t solve this 1500 question…
The problem is to basically find whether a exists that
I tried alot of ideas like turning it into a polynomial and binary search, try to find a formula for f…
But everything didn’t work. Sad and defeated, I went and checked the editorial.
It turns out the solution was really straightforward:
There is actually a bound when the remainder for starts looping!
The bound is actually , where I will give a proof quickly here (Alhtough should be moderately obvious):
, so in this function when .
So the solution is to try the first numbers… how disappointing :/
To be honest, I don’t know how to make sure I can solve questions like this next time, maybe just practice more…
Code
1 | void solve() { |
Time Complexity:
CF 1081A. The Very Beautiful Blanket
I already encounter this question a long ago, but this was a really telepathic constructing problem.
The solution is just to construct 2x2s by , , , . It’s magic that is actually works in my opinion.
Not sure how would I come up with this on my own, so uh lets just check out my code lol
Code
1 | void solve() { |
Time Complexity:
CF 1731D. Valiant’s New Map
Finally a question I fully solved myself! (1700 too lol)
The question is for each test case , you want to find the maximum such that
you can find a square in a grid where every element is greater or equal to .
Well, a easy idea is to binary search , enumerate through every square and do 2D range min queries!
This is just a basic binary search + 2D range min query right? 2D sparse table lets gooooo!
Funnily enough, 2D ST is actually a solution that was given in the tutorial (albeit a bit overkill),
and 2D segtree actually wouldn’t pass due to each query.
Lets try to solve it in an elegant manner instead of overkilling with weird data structures!
Of course when talking about 2D queries, you would recall that you could do 2D prefix arrays.
But thats for 2D range sum queries, how to we transform the question into checking range sums?
Notice that if we let , we would get a array with only zeros and ones,
then if we do prefix sum, a query that equals to means that every element inside is greater or equal to !
Code
1 | int n, m; |
Time Complexity:
Pretty elegant solution right?
CF 1114C. Trailing Loves (or L’oeufs?)
This problem is super hard for me… pure math is just death for me XD
The problem is to find the number of trailing zero digits when representing in base .
It is also equivalent to finding the max such that is divisible by . (Makes alot of sense if you think about it).
Well, the observations above are still pretty reasonable, but is a super big number! how do we do this?
Apparently, there is an exact formula dealing with this problem: Legendre’s Formula
The formula states that the largest such that is divisible by is .
I was confused by this formula at first, but it made sense after some thinking:
, how many numbers between to are divisible by ? numbers.
Now we counted the numbers divisible by , but we only counted the numbers divisible by once when they should contribute twice. So what we do is do this for every power of and sum up the values to get what we want.
The formula requires the base to be prime though, while we have any number in .
What we can do is to prime factorize as and apply the formula with every prime factor to obtain .
Finally, we can get the answer for by .
Code
1 | void solve() { |
The code also had alot of specific parts that needed some attention when writing, I realized that 0x3f3f3f3f only equals to around , which is not enough for this question.
Another thing was deciding the bound for . I wrote , but this actually causes overflow, you need to change to to prevent overflow from happening.
This was a really interesting question that troubled me alot, really shows that I need to up my math game.
