Some thought about CP + some CF
I’m seriously considering whether I should try pursuing CP in college. I did CP in highschool before, and really didn’t achieve much. The main thing I should think about is what I can get from doing CP in college.
I talked to Kuroma yesterday and I decided to give myself one year for CP:
If I can’t get in ICPC or can’t get to atleast master in CF I’ll quit and focus on DL. I think this is a solid plan do really determine if I should spend my time on this, hope I can do it!
I’ve also contacted a previous member of UW Madison’s ICPC team–RobeZH. I was really inspired and shock when I saw in his blog that he only started CP in his undergrad, and within only 4 years he became IGM and did successfully in ICPC. I hope to know more about CP in Madison and I wish to become as good as him.
Another thing is that I went and contacted a former friend of mine which I thought I would never forgive him. There was a annual team-based algorithm contest and we went as a team before. For last years contest, he replaced me with another person that barely knows how to code, and didn’t notify me whatsoever. I was in a really dark time and this really made me collapse. I thought we were good friends and he wouldn’t do something like this. I blocked him everywhere and I absolutely hated him since.
After a whole year and being in a better position, I was talking with one of our mutual friend who did well in the college entrance exam. He mentioned that he was really sorry and wanted to apologize to me. I was in dilemma because I thought it would be super awkward. I told the friend to tell him that I wish him the best luck at Singapore (He is going to NTU). I told my counselor about this and she encouraged me to ask him about why he didn’t invite me.
I was like ok fuck it the worst thing thats gonna happen is I hate him more, I have nothing to lose! So I went and questioned him.
The reason he gave me was he was in a hurry and genuinely did not think that much. This was such a bad reason that it actually made me laugh. Although after alot of thinking, I realized that there is basically no point to hate him really, and him giving a bad reason without even trying to come up with a better one really made me chuckle, so I just kinda forgave him. I don’t think we could be as good as a friend like before, but hey, at least I don’t hate him anymore.
Well, enough for recent updates and lets check out some CF problems :D
CF 1336A. Linova and Kingdom
This problem is a problem I mindsolved at the salon but didn’t implement until today.
You are given a tree with () nodes and 1 as the tree’s root.
There are two kind of nodes–Industry node and tourism node.
The happiness is defined as the number of tourism nodes on the path from a industry node to the root. (The root can also be a tourism node or industry node)
Given a value (), You must assign nodes as industry nodes. What is the maximum possible sum of happiness achievable?
There are a few observations we can easily notice:
We should always choose the ones with the deeper depth on a path, as it would give us more possible happiness compared to chosing one with a smaller depth.
We can let every node be a tourist node, and try assigning industry nodes and calculate the changes each industry node made.
Now, lets try to figure out the happiness a node with depth and a subtree size of provides.
Obviously, the number of tourism nodes on the path to the root is just equal to . But we also need to take account for the happiness taken away from changing it from a tourist node to a industry node.
The total ammount of happiness taken away is equal to the size of the subtree . So for a industry node with depth and a subtree size of , The total happiness it contributes is .
Now we can just greedily choose nodes that contribute the highest happiness and AC this question!
Code
1 | const int MAXN = (int)2e5 + 5; |
Time Complexity:
Next off are questions all from CF Round 890 (Div 2), I couldn’t participate in time unfortunately :/
The statements are all super clear so I’ll omit the part explaining the statements.
CF 1856A. Tales of a Sort
A trivial problem so I’ll just provide my code and skip this question…
Code
1 | void solve() { |
Time Complexity:
CF 1856B. Good Arrays
There is a easy solution to this: We can set all 1’s into 2, and anything not equal to 1 as one. Now if the current sum is smaller or equal to the original sum, it’s possible, else it isn’t.
The idea is quite simple here. We make sure everything satifys , and if the sum is less then the original one, it’s not hard to see that we can just put the remaining needed values on one index.
Code
1 | void solve() { |
Time Complexity:
CF 1856C. To Become Max
(notice that )
I initally thought this problem was super easy and quickly came up with a greedy solution, just to be proven wrong by one of the samples.
The idea is for each index, we use binary search to find the maximum value this index can become.
lets say for an index with a original value , and we want to check if making it become is possible or not:
if it’s obviously possible.
else, we add a cost of and start checking and modifying indexes on the right:
for each index on the right, we only need it to become for to become .
if we encounter one that already satisfys this condition, we can stop and check if the overall cost is higher than what we have.
The same goes for when we get to the end, except we also need to check if the last element is large enough.
Code
1 | int n, k; |
Time Complexity:
CF 1856D. More Wrong
Well… this was a tricky question.
I did thought of the crucial part of solving this question, but I just couldn’t assemble it.
Another thing is that im just not that good with D&Q problems.
The thing I observed quickly is this:
Denote as a query of , if , is bigger than every value in the sub array .
I failed to realize that if I know the biggest index in two adjacent sub arrays, I can use this idea to find which one is bigger!
The whole solution is as follows:
We divide the arrays into several subarrays of 2 (there will be one with only 1 index if it’s odd).
For the subarrays of 2, We each ask a query to determine which is bigger. (the index if theres only 1 index)
Now we recursively do the following:
For each two adjacent subarrays and with this largest index at and , I can ask 2 queries, and , to determine which is bigger. (if we just ask )
And the final biggest index is what we want!
The formal proof for cost is in the editorial,
although we can also get an extremely rough estimate of the cost:
Code (Note that my implementation is pretty bad, check out the editorial for a concise version!)
1 | int solve(int l, int r) { |
Time Complexity:
