zltzlt's blog

By zltzlt, 17 months ago, In English

Thanks for participation!

2084A - Max and Mod

Idea: zltzlt

Hint 1
Solution
Implementation

2084B - MIN = GCD

Idea: zltzlt

Hint 1
Hint 2
Solution
Implementation

2084C - You Soared Afar With Grace

Idea: CharlieV

Hint 1
Hint 2
Solution
Implementation

2084D - Arcology On Permafrost

Idea: zltzlt

Hint 1
Hint 2
Hint 3
Solution
Implementation

2084E - Blossom

Idea: zltzlt

Hint 1
Hint 2
Solution
Implementation

2084F - Skyscape

Idea: zltzlt
Developer: 244mhq

Hint 1
Hint 2
Solution
Implementation

2084G1 - Wish Upon a Satellite (Easy Version)

Idea: zltzlt

Hint 1
Hint 2
Solution
Implementation

2084G2 - Wish Upon a Satellite (Hard Version)

Idea: zltzlt

Hint 1
Solution
Implementation

2084H - Turtle and Nediam 2

Idea: zltzlt
Developer: StarSilk

Hint 1
Hint 2
Hint 3
Solution
Implementation 1
Implementation 2
  • Vote: I like it
  • +122
  • Vote: I do not like it

| Write comment?
»
17 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

for C I created a graph for the target positions of each index and then ran a dfs. There will be a cycles and we need size — 1 steps to reach out target and graph building got me a WA :(((

  • »
    »
    17 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    you don't need to put the pairs such that a[i] = i in the end. You just need to ensure in the end that if some pair (a[i], b[i]) exists, that (a[j], b[j]) = (b[i], a[i]) exists for some other j as well. You can place them at ANY symmetric positions about the middle.

  • »
    »
    17 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    for C I swap and pray, after swapping I check one last time if all match -> YES/NO.

    And it works like a charm.

  • »
    »
    17 months ago, hide # ^ |
     
    Vote: I like it +5 Vote: I do not like it

    a piece of advice: Think more deeply and plan thoroughly before you start writing.

»
17 months ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

so quick tho

»
17 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

The Penalties got us fr , could've avoided so much of penalty this contest!!

»
17 months ago, hide # |
 
Vote: I like it +34 Vote: I do not like it

The checker message Jury has the better answer: jans = 2, pans = 0 helped me figure out that I need to find $$$f(a)$$$ to solve D lmao

»
17 months ago, hide # |
 
Vote: I like it +28 Vote: I do not like it

The Permutation Contest

»
17 months ago, hide # |
 
Vote: I like it +70 Vote: I do not like it

Difficulty gap from D to E is ridiculous

»
17 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

C messed up the whole contest, but D was saver

  • »
    »
    17 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    D messed up the whole contest, but E was saver

    • »
      »
      »
      17 months ago, hide # ^ |
      Rev. 2  
      Vote: I like it 0 Vote: I do not like it

      can you explain your solution for problem E.

      Update: Thank You for the well explained solution.

      • »
        »
        »
        »
        17 months ago, hide # ^ |
         
        Vote: I like it +12 Vote: I do not like it

        Firstly, you need to do some transformations of the statement.

        Define $$$mex(a)$$$ as the number of $$$k$$$'s such that every number in the range $$$[0, k]$$$ is present in $$$a$$$. This number actually equals to $$$mex$$$, because by the definition, all numbers from $$$0$$$ to $$$mex - 1$$$ are present and $$$mex$$$ is not present.

        Also, let's count the contribution of each subarray independently. Now, you can sum up the contributions of each $$$k$$$ separately. For this purpose, you can brute force the value of $$$k$$$. It is possible to make all integers from $$$0$$$ to $$$k$$$ appear in the subarray if the subarray contains all the fixed positions where $$$a_i \le k$$$, because if this doesn't satisfy, i.e. there's a value $$$\le k$$$ in the whole array, but not in the subarray, then you should repeat that value $$$2$$$ times to make this value appear in the subarray.

        Now, let's keep track of the minimum/maximum position of a fixed element that is $$$\le k$$$, let's denote them as $$$[lx, rx]$$$ correspondingly. Then, for the subarray $$$[l, r]$$$ to have a positive contribution, it should contain the segment $$$[lx, rx]$$$.

        To calculate the contribution of segment $$$[l, r]$$$, let's denote $$$cnt$$$ as the number of elements that are $$$-1$$$ in the current segment, and let's denote $$$miss$$$ as the number of elements in the array that are $$$-1$$$, and let's denote $$$x$$$ as the number of elements that are $$$\le k$$$ that aren't present in the array. The contribution becomes $$$P(cnt, x) * (miss - x)!$$$ . This is because you must insert those $$$x$$$ missing elements $$$\le k$$$ in the subarray to make all of them appear, and you can insert them in any order and in any position that is $$$-1$$$ in the subarray, so the number of such arrangements is $$$C(cnt, x) * x!$$$, or $$$P(cnt, x)$$$. And all other $$$miss - x$$$ elements can be inserted arbitarily into $$$-1$$$ positions, so the number of those arrangements is $$$(miss - x)!$$$ . Together, the number of ways equals to $$$P(cnt, x) * (miss - x)!$$$ .

        To calculate this value fast, you need to fix the $$$cnt$$$, because $$$miss$$$ and $$$x$$$ are the same for all the subarrays. For each $$$cnt$$$, you should save the number of segments that contain $$$[lx, rx]$$$ and have the number of missing elements equal to $$$cnt$$$. Now you can notice that the number of $$$[lx, rx]$$$s for which the answer should be calculated equal to $$$n$$$, $$$k$$$ can take the maximum value of $$$n - 1$$$, so you can fix $$$cnt$$$ for each of those segments independently.

        Let's iterate $$$rx$$$-s in decreasing order and add segments which have $$$r \ge rx$$$ and take a fenwick tree for each $$$cnt$$$. For each of those segments $$$[l, r]$$$, you need to add $$$1$$$ to the $$$l$$$-th position of the $$$cnt$$$'th fenwick tree. Now, the number of segments that contain $$$[lx, rx]$$$ and have the number of missing elements equal to $$$cnt$$$ is given by the $$$sum(1, lx)$$$ in the $$$cnt$$$-th fenwick tree. Basically, among segments with $$$r \ge rx$$$, you calculate the number of those with $$$l \le lx$$$. For more implementation details, you can look at my code.

»
17 months ago, hide # |
 
Vote: I like it +17 Vote: I do not like it

Problem C is really interesting. Thanks for the round and very fast editorial

»
17 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

A little typo: in problem B, time complexity for finding the gcd of $$$n$$$ numbers is $$$\Theta(n+\log a)$$$ instead of $$$\Theta (n\log a)$$$.

»
17 months ago, hide # |
 
Vote: I like it +20 Vote: I do not like it

Literally there is no graph , dp , binary search , greedy , etc... in A-D problems.

it is only based on mex and permutation .

like why now a days , the contest are going bad and bad ?

  • »
    »
    17 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    D is greedy and C feels as well , the thing is that on lower level(or my level) questions they have started giving constructive or less — pattern based more to avoid AI based cheating

  • »
    »
    17 months ago, hide # ^ |
     
    Vote: I like it +4 Vote: I do not like it

    C is graphs and cycle. Check my submission

    Also, I politely disagree with you. This is one of the best rounds recently on codeforces. The problem quality was amazing

»
17 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

can anyone help me with this doubt with problem B..can anyone explain why if i iterate over all the elements in the vector divisible by minimum element given to find a pair if its gcd is equal to minimum element if i find then i just print yes....then it should not give wrong answer in o(n^2) time complexity..it would have given tle ...but it gave wrong answer....if i take gcd of all elements divisible by minimum element it shows accepted how?? i mean let g = gcd(b,c,d....z),where a|b,c,d,...z; so g should be equal to either of (gcd(b,c...z),gcd(c,d....z),gcd(d,e....z),...gcd(y,z)) right?

  • »
    »
    17 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +2 Vote: I do not like it

    Let $$$G = \gcd(a_1, a_2, \dots, a_n)$$$.

    For any pair $$$(a_i, a_j)$$$, we have: $$$G \mid a_i$$$ $$$\text{and}$$$ $$$G \mid a_j$$$ $$$\Rightarrow G \mid \gcd(a_i, a_j)$$$ $$$\Rightarrow$$$ Thus, $$$\gcd(a_i, a_j) \geq G$$$

    Let the array be: [2, 12, 20, 30]

    • min = 2
    • gcd(12, 20, 30) = 2 = min

    So we can split as:
    Prefix = [2], Suffix = [12, 20, 30]min = gcd = 2YES

    But pairwise GCDs are:

    • gcd(12, 20) = 4
    • gcd(12, 30) = 6
    • gcd(20, 30) = 10

    None equal to 2, hence pairwise checking fails. Must take gcd of all divisible-by-min elements.

»
17 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

nice C and nice D. but E is too hard for me :)

»
17 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

B's complexity is $$$O(n + \log mn)$$$ I guess, since $$$\gcd$$$ reduces $$$\log$$$ times, or it does not change. After $$$\gcd$$$ becomes $$$mn$$$, $$$\gcd$$$ function is calculated in $$$O(1)$$$.

»
17 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Kind of a dumb question, but for problems like C, do we always need to assume that we need to output the minimum number of operations needed? I got that problem wrong because of that :( ...

  • »
    »
    17 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Generally, I maintain a rule of thumb that it's good to highlight keywords such as minimize, maximize, etc. I have had an unpleasant amount of WAs because I'd just skim over those words and forget about them when modeling the solution.

    If you highlight those keywords, you can then determine whether or not you should minimize/maximize or whatever it is you have to do.

    On a separate note, sometimes it's easier to make a strategy that always minimizes the number of operations and sometimes it is not. If it's easy to make such a strategy (and you can more or less prove that it's always optimal), then you should use it. Otherwise, such as in the case of problem C (I personally just avoided that line of thought as I figured it would waste more time), it's easier to come up with a strategy that just works and doesn't minimize the number of operations + the statement didn't have any of those keywords, because of which we aren't restricted.

    • »
      »
      »
      17 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      yeah what happened was that I didn't consider the case where if n was odd and if the index where the numbers were the same on a and b (ex: n = 5, and a[3] = 4 and b[3] = 4), then I wouldn't need to do a swap to the middle. I just swapped the element that has the same values to the middle always without considering this case, figuring it wasn't important as the solution didn't require you to minimize the swaps.

»
17 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

Can anyone please share their approach for problem E? I didn't quite understand any part from the editorial for E.

  • »
    »
    17 months ago, hide # ^ |
    Rev. 10  
    Vote: I like it +17 Vote: I do not like it

    Formula Calculation :
    Missing = array of all the numbers that do not appear in the original array

    For a range [l,r], spotted = number of -1's present in the range
    total = number of -1's in the original array
    non-spotted = total — spotted = number of -1's present outside the range
    idx = index of the maximum number in Missing that can contribute to MEX of the range
    Eg. Permutation: [-1, 0, -1, -1, 3, -1]
    => Missing = [1,2,4,5]
    In range [1, 4], spotted = 3 and idx = 2
    (Note that the maximum MEX for the range is 3, but it is not present in the Missing Array)

    Claim: Every element in Missing having index <= idx can be made the MEX of range [l,r]
    Proof: Let's say we want Missing[i] $$$(i \lt =idx)$$$ as the MEX of the range,
    Choose i-1 positions from the spotted -1's, insert all the elements with index<=i
    and 1 position from non-spotted -1's and insert Missing[i].

    So we reduce down to calculating the number of ways in which $$$Missing[i]$$$ become MEX for a range.
    => Number of ways = C(spotted, i-1) * (total — spotted) * (i-1)! * (total — i)!
    => Contribution of i = Number of ways * Missing[i].

    Now we can simply precompute the Contribution for all possible pairs of (spotted, i) in O(N^2).

    An another number which can contribute as a MEX for a range is the MEX we generate by putting all the missing elements ideally.
    For eg. Permutation: [-1, 0, -1, 3, -1]
    => Missing = [1,2,4]
    In range 1 to 3, if we put 1 at index 1 and 2 at index 3, the MEX of [1,3] is 3.
    Let this number be Ideal MEX.
    We can compute the contribution due to Ideal MEX for a range by:
    => C(spotted,idx) * idx! * (total-idx)! * Ideal MEX.

    For O(N^3), we can iterate over all possible range and calculate the contribution for each i.
    This can be optimised to O(N^2)
    For a given range, sum of the value of all possible valid permutations(answer) = summation of contribution due to Missing[1] + Missing[2] + .. Missing[idx] which can be precalculated using prefix sum.

»
17 months ago, hide # |
 
Vote: I like it -12 Vote: I do not like it

IDK but D feels like 1300, C was more difficult than D I guess

»
17 months ago, hide # |
 
Vote: I like it +49 Vote: I do not like it

Can you please write proper editorial for problem E? Especially optimization part

  • »
    »
    17 months ago, hide # ^ |
     
    Vote: I like it +47 Vote: I do not like it

    This is my solution:

    Firstly, we can calculate the expected MEX values for all ranges independently. Let's assume we are calculating for a specific range $$$[L, R]$$$. Let $$$emp$$$ be the number of $$$-1$$$'s in the range $$$[L, R]$$$, and let $$$all$$$ be the total number of $$$-1$$$'s in the entire array.

    Instead of summing the expected MEX values as $$$\sum_{\text{mex}} (\text{how many permutations have MEX equal to } \text{mex}) \times \text{mex}$$$, we will instead sum as $$$\sum_{\text{mex}} (\text{how many permutations have MEX} \geq \text{mex})$$$, without multiplying by the MEX.

    Suppose we want to compute the number of permutations where $$$\text{mex} = m$$$. Then, every integer $$$i \lt m$$$ must appear in the range $$$[L, R]$$$. If any such $$$i$$$ does not appear, then there are no valid permutations with MEX $$$\geq m$$$.

    Let $$$bon$$$ be the number of integers $$$i \lt m$$$ that do not appear in the range. Then the number of permutations with MEX $$$\geq m$$$ is $$$\frac{emp! \times (all - bon)!}{(emp - bon)!}$$$.

    This works because we choose $$$bon$$$ positions among the $$$emp$$$ empty slots to assign the missing values $$$i \lt m$$$, and the remaining $$$emp - bon$$$ slots can be filled with the remaining $$$-1$$$'s, while adjusting for the total permutations using the factorials.

    It's clear that this can be computed for all MEX values in $$$O(N^3)$$$ time: 314148419.

    We can optimize this using prefix sums: precompute values for all possible $$$emp$$$ and MEX values, and for each query, just check whether all integers $$$i \lt m$$$ are present in the range. My current implementation runs in $$$O(N^2 \log N)$$$, but I believe it can be optimized to $$$O(N^2)$$$: 314152700.

    • »
      »
      »
      17 months ago, hide # ^ |
       
      Vote: I like it +14 Vote: I do not like it

      You're right, and removing the log is actually quite simple. You can refer to my implementations during and after the contest: 314135087 and 314183843. The main idea is that the maximum possible MEX will never decrease as R increases, so you can just maintain it with two pointers.

»
17 months ago, hide # |
 
Vote: I like it -9 Vote: I do not like it

Problem C Never mentioned to output minimum number of operations.

It clearly says, "If it is possible, output any valid sequence of operations. Otherwise, output −1 ".

I could not solve this problem during contest because of this and so many others would have faced the same problem. This needs to be addressed...!!!

  • »
    »
    17 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Yeah I had the same issue too lol, I assume that they would usually say print the minimum number of operations, right?

  • »
    »
    17 months ago, hide # ^ |
     
    Vote: I like it +16 Vote: I do not like it

    You don't need to output the minimum number of operations thou...

    • »
      »
      »
      17 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      You can check my two submissions and that is what got me WA

      • »
        »
        »
        »
        17 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        No your code is wrong check the judge result it says p[1] = q[1], not too many operations used or something

        • »
          »
          »
          »
          »
          17 months ago, hide # ^ |
           
          Vote: I like it -8 Vote: I do not like it

          It said the same for me, yet when I changed my code to correct one specific case where if the middle element had the same indices, then I wouldn't need to do a swap (I did a swap which used an extra operation unneccesarily), it was AC.

          • »
            »
            »
            »
            »
            »
            17 months ago, hide # ^ |
            Rev. 3  
            Vote: I like it +11 Vote: I do not like it

            From the statement:

            You can perform the following operation at most $$$n$$$ times: Choose two indices $$$i$$$ and $$$j$$$ ($$$1 \leq i, j \leq n$$$, $$$i \neq j$$$)...

            Note that it says $$$i\neq j$$$. Both yours and MaheshDA's submissions output an operation on 2 2 for the test case:

            3
            1 2 3
            3 2 1
            

            which clearly violates this condition.

»
17 months ago, hide # |
 
Vote: I like it +14 Vote: I do not like it

In E's solution:

There are exactly $$$k$$$ -1s

I believe it's supposed to $$$c_1$$$ not $$$k$$$. zltzlt

»
17 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Anyone ~ why this is giving WA , 314126993 , on PreT 3 ?

  • »
    »
    17 months ago, hide # ^ |
     
    Vote: I like it +8 Vote: I do not like it
    1
    4
    2 30 42 70
    

    should output YES because $$$\gcd{(30, 42, 70)} = 2$$$ but your submission outputs NO.

»
17 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For problem C, does anybody know why the following strategy of doing the swaps fails?

  • Store the indices of symmetric pairs in a map. Say a[i] = b[j] = x, and b[i] = a[j] = y, for some 1 <= i, j <= n, then we have mp[{min(x, y), max(x, y)}] = {i, j}.

  • Keep a counter (initially 0) and loop through each pair p:

  • If p is the pivot for odd n (i.e. p.first == p.second), ignore it.
  • Otherwise, swap the two pairs at indices (p.first, p.second) with the pairs at (counter, n - counter - 1) respectively.

Here is the submission: 314141297

»
17 months ago, hide # |
 
Vote: I like it +30 Vote: I do not like it

Look, it's nice that there's hints in editorials these days, but those hints need to match difficulty of the problem. Take hint 1 of F, for example: it's offering 0 new information, instead it's (rephrasing) just "read and comprehend the problem statement". Here's an example of a much better hint:

Spoiler

Perhaps extremely basic handholding hints that point people to look for the obvious, to "speak math language" in general, are useful for early problems, but they won't help anyone who can actually solve a harder problem with hints without looking at a solution. That should be the criterion: can we reasonably expect anyone to be good enough to solve a problem just looking at hints up to K, but unable to figure out hint K on his own?

»
17 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
»
17 months ago, hide # |
 
Vote: I like it +7 Vote: I do not like it

I think there might be a minor error in the Problem E solution—shouldn't it be $$$c_1 = i, k = j$$$?

»
17 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

This C makes me very annoyed because it's extremely difficult to debug.

»
17 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

I'd like to know how to write the checker for problem D,does there exist a solution of complexity O(n)?

»
17 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anyone pls tell me why this fail problem C:

code...

»
17 months ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

Although E is difficult(I think the difficulty is 2400),E is an excellent problem!

»
17 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Can anyone just explain the approch in layman terms for problem E, Everyone is focusing on the implimentation, but I just want to know how it got there.

  • »
    »
    17 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Let's say the permutation is filled. How many intervals have MEX > 0? Add that to the answer. How many have MEX > 1? How many have > 2? Etc. At the end, every interval is added to the answer as many times as its MEX.

    When the permutation is unfilled, at each of these steps where we're counting MEX > $$$m$$$, the cost of each interval isn't 1 but the number of permutations we can make such that this interval has MEX > $$$m$$$, i.e. it contains everything in $$$[0, m]$$$. That's the formula with factorials.

    For a given $$$m$$$, the formula only depends on the number of unfilled positions $$$f$$$ in a given interval; the number of intervals can be large, but $$$f \in [0, N]$$$ so we want to count how many intervals have a given $$$f$$$; answer is (sum of cost * count over $$$f$$$) over $$$m$$$.

    Last thing to deal with is that as $$$m$$$ increases, some intervals become impossible — we're only counting those that contain all the values in $$$[0, m]$$$ that are filled at the start, so they're superintervals of $$$I$$$ = [min position, max position of those filled values]. As $$$m$$$ increases, this interval $$$I$$$ increases too, so we can just remove those intervals from the counting above, each will only be removed once.

»
17 months ago, hide # |
 
Vote: I like it +9 Vote: I do not like it

The editorial for E says $$$d_{x,0},d_{x,1},\dots,d_{x,y-1}$$$, but shouldn't it be $$$d_{0,x},d_{1,x},\dots,d_{y-1,x}$$$ based off of the definition of $$$d_{i,j}$$$?

»
17 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

I have a slightly different implementation of H. I think it is a bit simpler: 314754662.

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For problem G2, I have a solution whose correctness I don't know how to prove. You can see it here:the link. The intrinsic interpretation is that the positrons and the electrons must be distributed as uniformly as possible, thus we only need to consider the states where the number of positrons and the number of electrons near each other.

»
15 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

My submission for E (Blossom) gets TLE on test-7 despite being O(n^2). Could someone help me figure out the issue?

Submission ID: 323239191

»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
void solve() {
    int n, m, k;
    cin >> n >> m >> k;

    int l = n / (m + 1);
    int deletions_per_op = (k + l - 1) / l; // ceil(k/l)
    int T1 = n / ((m + 1) * deletions_per_op);

    // at least k
    int T2 = k;

    int T = max({T1, T2, 1ll}); // 至少为1

    For(i, n) { cout << i % T << ' '; }
    cout << '\n';
}

solving D in O(1)

»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For B, why are we putting all the numbers that are

  1. divisible by min(a) and
  2. not equal to a

on the right (GCD) side? For example, the numbers in the array could be p*min(a) and p*q*min(a) — these two are divisible by min(a), but their GCD is p*min(a), not min(a). Why not put p*min(a) in the left (MIN) side instead?