|
+16
I also used GCC 7 (32-bit) on the contest yesterday, but my submission passed without any issues: 297315717. Arguably, my code is even worse because I am creating and returning a new After a bit of experimenting, here is what I can share:
The takeaway? I honestly don't know. But I will definitely stick to GCC 14 (64 bit) from now on. |
|
+4
I solved it in a different way than described in the editorial. First of all, notice that for any rectangle with even lengths, odd sum and even sum are completely symmetric. Thus, for some $$$2n \times 2m$$$ matrix we can take the answer as just $$$sum / 2$$$. Then, if either width or height of a rectangle is odd, you could separately add one row and one column to the answer. If both of them are odd, don't forget to subtract the contribution of one cell in the border because we count it twice. |
|
+9
Wait, the statement says you have to do $$$(+\ 1)$$$ and $$$(\times\ 2)$$$ both simultaneously in one operation. Moreover, it is not allowed to have $$$i = j$$$. Or am I missing something? |
|
+14
|
|
+4
I have a solution to problem E which does not involve graphs in any way. At the beginning, our array values fit in range $$$[0, 2^{30}]$$$. Let's now divide the array into two parts $$$L$$$ and $$$R$$$, where $$$L$$$ will contain all values $$$\le 2^{29}$$$ and $$$R$$$ will contain all larger values. Now suppose $$$(x, y)$$$ is the optimal pair we are searching for. Here comes a crucial observation. If both $$$(x, y)$$$ are in $$$R$$$ they are both larger than $$$2^{29}$$$ so we cannot use any $$$k \le 29$$$ operation on them. The only way to continue is to use $$$k = 30$$$ and make them both less than $$$2^{29}$$$. Also suppose $$$x \le 2^{29}$$$ and $$$y \gt 2^{29}$$$. In this case we have to transfer one value to the other side by using $$$k = 30$$$, but transferring $$$x$$$ is never optimal. Let's prove it. Case $$$x = 2^{29}$$$ is trivial. Otherwise $$$x \lt 2^{29}$$$ so $$$2^{30} - x \gt 2^{29}$$$ and since also $$$y \gt 2^{29}$$$ we arrive at the previous state when we are forced to decrease both of them using $$$k = 30$$$. This means that it is always better to do an operation on $$$y$$$, again reducing it to some value $$$ \lt 2^{29}$$$ and continue from there. All the reasoning above means that all values $$$R$$$ have to be reduced in one operation to become less than $$$2^{29}$$$ and after that we can merge those values with $$$L$$$ and repeat our algorithm again with a threshold $$$2^{29}$$$. We can repeat this process until we arrive at a simple case when all values are in range $$$[0, 1]$$$. Here we can just consider a transition $$$0 \rightarrow 1$$$ and we are done. This solution can be implemented in various ways. One I can think of is to store $$$L$$$ and $$$R$$$ as sorted vectors and merge them using two pointers. But I personally think that maps are the most simple and elegant way. Maps introduce an additional $$$\log n$$$ factor, resulting in a $$$O(n \log n \log 10^9)$$$ solution overall which is still fast enough considering a very generous time limit. Here is my submission: https://codeforces.me/contest/1617/submission/139683868 |
|
+25
I would probably do it this way: code But note that it doesn't work when $$$n = 1$$$ or $$$m = 1$$$ so you will probably have to run a simple loop for that. |
|
0
Same. Tool and Opeth are my favourites. |
|
+3
The reason your Your code gets AC without |
|
On
Harbour.Space →
Harbour.Space Scholarship Contest 2021-2022 (Div. 1 + Div. 2) Editorial, 5 years ago
+15
Suppose you have a connected component of size $$$k$$$. It will surely be a cycle. You can easily show that this cycle can be fixed using $$$k-1$$$ swaps, but not less. In total this will sum up to $$$n - cycles$$$ operations. Also you could try mixing elements between different cycles, but you will see it does not help either. This is not a formal proof, just a simple explanation built on pure intuition and logic. |
|
On
Harbour.Space →
Harbour.Space Scholarship Contest 2021-2022 (Div. 1 + Div. 2) Editorial, 5 years ago
+73
Hey, I am an author of problem F. We actually did not intend any $$$O(N \sqrt{M} \log M)$$$ solutions to pass at the beginning. The thing is, my Fenwick tree solution works in ~400 ms, but my segment tree solution works in ~2.5 s. Segment tree with pushes does not even pass the time limit because of a high constant factor. Also we had to care about Java solutions, so I decided to raise the TL from 3s to 4s, letting $$$O(N \sqrt{M} \log M)$$$ to pass. I know I had to fix this problem in a more adequate way by experimenting with constraints. Will certainly do that in future rounds. Sorry about that. |
|
+5
There is a small mistake in your explanation. Actually, you need to multiply A by B in power of f(P)-1 and f(P) for prime number is P-1. |
|
+3
Okay, I will try to explain. You need to understand that if there is a vertex A and a vertex B, and A is parent of B, you ALWAYS need to paint A first. Why? Because if we paint B, then A, the color of B becomes the same as the color of A (don't forget that A is parent B). So you will need to paint it again, which is not optimal. That's why we need to start painting from the root of tree. |
|
0
Maybe you're asking about simple segment tree. Try to google "minimum query segment tree" in google. |