### maroonrk's blog

By maroonrk, history, 4 months ago, We will hold AtCoder Regular Contest 136.

The point values will be 300-400-500-600-800-1000.

We are looking forward to your participation! Comments (62)
 » oh , yes maroon-senpai go as hard as you always go >,<
 » why A has so long code
 » How to solve D?
•  » » I used a 6-dimensional Fenwick tree. And laughed out loud when it got AC.
•  » » » That's hardcore.
•  » » While you are thinking about D,I am working my head off on B without success.
•  » » » 4 months ago, # ^ | ← Rev. 2 →   I think the operation was equivalent to performing a simple swap operation 2 times. So, if an element occurs twice in array A, you can always make the array A equal to B. Otherwise check if you can make it equal by doing even number of swaps.
•  » » 4 months ago, # ^ | ← Rev. 3 →   You need to hold for each $X$ the number of elements $Y$ where for all $i$ in digit representation of $X$ and $Y$ $Y_i <= X_i$, You can do that by using inclusion-exclusion for example let's call the number of correct elements $F(x)$ so $F(99) = F(98) + F(89) - F(88)$.Now the answer is $\sum_{i=1}^{n} F(999999 - a_i)$ with some case handling for the $i < j$ part.
•  » » 4 months ago, # ^ | ← Rev. 2 →   SOS DP but with multisets.
•  » » 4 months ago, # ^ | ← Rev. 2 →   Maybe,you can use High-dimensional prefix sum(I got this name from translation,so it may be strange). This is my code:D
•  » » » Yeah,that's a good way to solve such problems
•  » » » Please explain your code or share some resources
•  » » » » 4 months ago, # ^ | ← Rev. 5 →   For example,you do as follows to get the 2-D prefix sum: for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) a[i][j]+=a[i-1][j]; for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) a[i][j]+=a[i][j-1]; After the first part,$a_{i,j}$ means $\sum_{x\le i,y=j}num_{x,y}$ .And when the second part is finished,$a_{i,j}$ means $\sum_{x\le i,y\le j}num_{x,y}$ .So when you do the k-D prefix sum,you can use the similar way to get the prefix sum from 1-D to k-D.In my code,I don't want to make special judge at the bound(when it meets 0,it's impossible to decrease by 1),so I add 1 on every digital which leads to the code may be strange.
•  » » » » » You can modify the bounds of your loops.
•  » » » wow, I always knew only O(2^D) way to build D-dimensional prefix sums...
•  » » » I also used High-dimesnsional prefix sum but in a noob way (it will make your day better) and your code looks like magic to me.
•  » » » » People before inventing loops:
•  » » 4 months ago, # ^ | ← Rev. 5 →   You can also use meet-in-the-middle, that is: Define $dp[i][j]$ where $i, j < 1000$, for how many number in array $A$ whose first 3 digits are equal to $i$ and last 3 digits are smaller than $j$'s 3 digits respectively. You can fix $i$ and enumerate for $j$ to compute $dp[i][j]$. Then define $dp2[i][j]$ for how many number in array $A$ whose first 3 digits are smaller than $i$'s 3 digits respectively and last 3 digits are smaller than $j$'s 3 digits respectively. Now you can fix $j$ and enumerate for $i$ to compute $dp2[i][j]$ using $dp[i][j]$. Lastly, compute the answer. It seems that we need calculate $10^9$ times, but it turns out that we only need about $3 \times 10^8$ times. My code is here https://atcoder.jp/contests/arc136/submissions/29758496
•  » » My approach was a bit different than the editorial.First calculate for each $1 \leq j \leq 1000000$, $dp[j]$ where $dp[j]$ means the number of elements in the array which have all digits greater than or equal to $j$. This part can be done by PIE. Let's now calculate the number of bad pairs instead. For each element, lets do inclusion-exclusion over the digits which will lead to carry-over. For example, in $21631$, digits $6$ and $2$ will lead to carry over if and only if the number to be added is of the form $y_{1}x y_{2} xx$ where $x$ can be any digit and $y_{1} \geq 8$ and $y_{2} \geq 4$. The number of such integers is stored in $dp$. Hence we perform PIE.Code
•  » » I used a 6-dimensional prefix sum, which can solve this problem in $O(N)$ time.Here is my code: D
 » This is by far the worst ARC ever.
•  » » I also had bad difficulties to solve B and C. Both where not simple because they looked like we could implement simulation, but turns out simulation is comlecated and actually not needed at all...That where kind of "better think twice" problems, which are not so bad, I think.
 » Thanks for such brilliant E! I was shocked by its beauty when I opened the editorial.
 » B: 40AC 3WA gang, checking in...so close, yet so just wrong...
•  » » 4 months ago, # ^ | ← Rev. 2 →   lol, I am : 42 AC ; 1 WAUPD : JUST GOT AC
•  » » There are two numbers that are equal to YES.
 » I think B is a good problem, which is even harder than D.It's pity that the data of B seems to be a little weak, and several of my friends got AC with wrong algorithm.
•  » » B can be solved in O(n^2) time (when counting inversions).If we had to use some kind of tree (eg. Fenwick) to get nlogn it would have been way harder.
•  » » » Or is my solution wrong? (it got AC)
•  » » » But counting inversions can also be done by merge sort, which is O(nlogn).
•  » » » » ah didn't know — but still it's not needed
•  » » » May I see your code write by counting inversions, because I got WA in this way...
•  » » » » It's not only about counting inversions — if there are two values that are the same then you don't have to care about parity of inversions.But here is my code if you want it: https://atcoder.jp/contests/arc136/submissions/29743627
•  » » » » » oh! I see, not only missed the two values are the same situation, but my implementation of counting inversions break at that time..., thanks~
•  » » » » » This problem really made me frustrated. I can't match this with inversion parites. How you come up with the solution during contest? or is this a well-kown puzzle that I miss?
•  » » » » » » it's pretty standard tbh
•  » » » » » » » Never thought about the use of inversion ~ really tough to figure it out by myself
•  » » » » » » » » I mean with the operation given in task you never change parity of inversions.So if initially parity of inversions is odd it will never be even and the other way around.So I guess linking the task to inversions is fairly forcing.What's hard is 'proving' that from every odd state you can reach every other 'odd' state.
•  » » » » » » » » » Maybe it's not hard actually.Like I don't know, I guess once you see similar problem you're going to link it to inversions pretty fast.But maybe if you've never seen anything similar (both in cs and math) then it might be hard, I agree.
•  » » » » » » » » » Thanks for sharing!
•  » » » » » » Indeed, it is a variant of the well-known puzzle called eight-puzzle, we can convert the task in it from matrix into a sequence to discuss. But this task is give you the sequence initially.
•  » » » » » » » Really helpful. I see some related issues on GeekforGeeks.
 » 4 months ago, # | ← Rev. 2 →   Shouldn't the definition of $e_n$ in problem F be starting from the given input state?
 » Hello, Can anyone explain the solution for problem B? I spent more than an hour to get no clue. I read the editorial but not very much clear. What is parity of the inversion number of an array?
•  » »
 » I think the following statement in $C$'s editorial for the case in which $M=D$ is incorrect:"Thus, it can be seen that an operation choosing a minimal segment containing all Ms will decrease both M and D by 1."Instead, I think we should find $2$ occurrences of $M$ where the region in between them has no $M$'s (call that region $reg$), then decrease all the array (except $reg$) by $1$. This should decrease both $M$ and $D$.
 » can anyone hack my solution of B ?
 » Problem B was a lot like 1591D - Yet Another Sorting Problem (which I find amusing because that contest generated a lot of controversy for using a problem that appeared on Atcoder). Also, problem C happened to be on the team round of the Harvard-MIT Mathematics Tournament which occurred last week (but the problems aren't posted yet). However, I still enjoyed this contest a lot, especially problem E.
•  » » Thanks. In the past few hours, I was trying to look for this problem 1591D. I remember such a question appeared which is like today's ARC 136B, and was trying to find out where did I see it.
 » I wonder what "carry" means in problem D...QwQ
•  » » It means that two numbers less than 10 add up to more than 10
•  » » » xie xie ni !!!
 » I think problem C is more difficult than problem D. The order of the two problem should be exchanged.
•  » » Could I ask why the solution counts the absolute differences of adjacent elements?
•  » » » I don't know, too. I use the solution that calculate max(0,a[i]-a[i-1]) .
 » Have a similar problem with C?
•  » » Maybe you can try USACO2022 Dec Bronze. The second problem is similar with C.
 » How should I solve problem B? Can someone give me some guidance?
 » 4 months ago, # | ← Rev. 2 →   In A, O(n) is even giving tle in python while in C++ it got ac in just 16ms that's why C++ is always better than any other language. (https://atcoder.jp/contests/arc136/submissions/29802542)
•  » » What does this s.pop(i) ? Does this like cut a char out of the string? If yes, it is most likely not O(1) operation.