Блог пользователя zltzlt

Автор zltzlt, 18 месяцев назад, По-английски

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
  • Проголосовать: нравится
  • +122
  • Проголосовать: не нравится

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 :(((

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

so quick tho

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

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

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится +34 Проголосовать: не нравится

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

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится +28 Проголосовать: не нравится

The Permutation Contest

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится +70 Проголосовать: не нравится

Difficulty gap from D to E is ridiculous

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

C messed up the whole contest, but D was saver

  • »
    »
    18 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    D messed up the whole contest, but E was saver

    • »
      »
      »
      18 месяцев назад, скрыть # ^ |
      ← Rev. 2  
      Проголосовать: нравится 0 Проголосовать: не нравится

      can you explain your solution for problem E.

      Update: Thank You for the well explained solution.

      • »
        »
        »
        »
        18 месяцев назад, скрыть # ^ |
         
        Проголосовать: нравится +12 Проголосовать: не нравится

        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.

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится +17 Проголосовать: не нравится

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

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

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)$$$.

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится +20 Проголосовать: не нравится

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 ?

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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?

»
18 месяцев назад, скрыть # |
← Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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)$$$.

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 :( ...

  • »
    »
    18 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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.

    • »
      »
      »
      18 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      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.

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

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

  • »
    »
    18 месяцев назад, скрыть # ^ |
    ← Rev. 10  
    Проголосовать: нравится +17 Проголосовать: не нравится

    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.

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится -12 Проголосовать: не нравится

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

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится +49 Проголосовать: не нравится

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

  • »
    »
    18 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится +47 Проголосовать: не нравится

    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.

    • »
      »
      »
      18 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится +14 Проголосовать: не нравится

      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.

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится -9 Проголосовать: не нравится

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...!!!

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

In E's solution:

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

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

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится +30 Проголосовать: не нравится

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?

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится +7 Проголосовать: не нравится

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

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
18 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone pls tell me why this fail problem C:

code...

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

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

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

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.

  • »
    »
    18 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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.

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

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}$$$?

»
18 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
16 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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?