TheScrasse's blog

By TheScrasse, 8 months ago, In English

2151A - Incremental Subarray

Author: TheScrasse
Preparation: TheScrasse

Hint 1
Hint 2
Solution

2150A - Incremental Path

Author: TheScrasse
Preparation: TheScrasse

Hint 1
Hint 2
Solution

2151C - Incremental Stay

Author: TheScrasse
Preparation: TheScrasse

Hint 1
Hint 2
Solution

2150B - Grid Counting

Author: TheScrasse
Preparation: Dominater069

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Hint 6
Solution

2150C - Limited Edition Shop

Author: TheScrasse
Preparation: TheScrasse

Hint 1
Hint 2
Hint 3
Solution

2150D - Attraction Theory

Author: Dominater069
Preparation: Dominater069

Hint 1
Hint 2
Solution Part 1
Hint 3
Hint 4
Hint 5
Solution Part 2

2150E1 - Hidden Single (Version 1)

Author: TheScrasse
Preparation: TheScrasse, Dominater069

Hint 1
Hint 2
Hint 3
Hint 4
Solution

2150E2 - Hidden Single (Version 2)

Author: TheScrasse
Preparation: TheScrasse, Dominater069

Hint 1
Hint 2
Solution

2150F - Cycle Closing

Author: TheScrasse
Preparation: TheScrasse, Dominater069

Hint 1
Hint 2
Solution

2150G - Counting Is Fun: The Finale

Author: satyam343
Preparation: satyam343

Solution
  • Vote: I like it
  • +155
  • Vote: I do not like it

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

is there any greedy solution for div2 E?

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

    I hope this code could help you^^

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

    Yes, here's how I did it:

    As editorial states, if Alice takes item $$$x$$$, she must also take all items $$$y \lt x$$$ that satisfy $$$pos_y \gt pos_x$$$. This condition is both necessary and sufficient.

    Now, the greedy solution is as follows: for each $$$i$$$ from $$$1$$$ to $$$n$$$, if $$$v_i \leq 0$$$, we should definitely not take it at this moment. Otherwise, let's find an unused item $$$j \lt i$$$ with the smallest $$$pos_j$$$ satisfying $$$pos_j \gt pos_i$$$. If no such item exists, the condition is already satisfied and we can simply add $$$v_i$$$ to our answer.

    Otherwise, if we ever end up taking item $$$j$$$, we will surely also take item $$$i$$$. Therefore, we can merge these two into a single item with $$$v' = v_i + v_j$$$ and $$$pos' = pos_j$$$. If $$$v' \gt 0$$$, we repeat this process again.

    Let me know if anything needs clarification.

    340848541

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

      wonderful solution

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

      beautiful solution. Thank You!

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

      "Otherwise, if we ever end up taking item j, we will surely also take item i." — I can sort of see why it holds when I think about it visually using a dependency graph, but I'm not able to come up with a proof for this. Is there any intuitive explanation for why this is the case?

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

        If we ever take item $$$j$$$, it means we must also have taken all other items with $$$k \lt i$$$ and $$$pos_k \gt pos_j$$$, and since $$$pos_j$$$ is the smallest position $$$ \gt pos_i$$$, this means we've also taken all items with $$$pos_k \gt pos_i$$$. Therefore, the condition is satisfied and we can take item $$$i$$$. Since item $$$i$$$ has $$$v_i \geq 0$$$, there's also no reason not to take it.

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

      really good solution

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

I've solved E12 slightly differently from the editorial one, but couldn't prove why it works well.

I had rec(l, r, b) where [l, r) is the range that contains shuffled indexes, and b is the values that appear only in [l, r) shuffled indexes. And checked every value in b if it appears in [l, mid), [mid, r) or in both. and descended in to the part with greater size of b. At the end we have r — l == 1 and |b| = 1, and b[0] would be the answer.

Part that made my code work from WA1 on E2 was descending to the range with greater size of the b. So if it fails to find the answer in the range with the greater size of b, it will descend to other half. Currently I don't know why that works.

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

    It is very interesting but your solution is equivalent to the editorial given (yes I think even the greater part)

    At recursion depth 0, you will go into the correct direction because if left is greater in size, it is also correct, and vice versa. In other recuesion depths, you are basically performing the binary search as in editorial.

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

      Ah lol, I am so stupid. Thank you!

      UPD: Wait, is it really? I don't think greater size means right range. That range just could contain more pairs

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

      Now I've done some experiments I think my code is not equivalent to the editorial one. It does like Editorial on the recursion depth 0, but after that it can visit both childs in recursion, because greater size doesn't mean it is the correct way to go. So I still have a question of why does it work so well (why does it use so few queries).

      code I am referring to 340210616.

      UPD: Also applying "going to the side with greater size" optimization only in depth 0 seems okay to pass the tests. Here is the code 340323716

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

        Yes so that is precisely what I said? Please read my comment again.

        At depth 0, you choose correct side. At other depths, you simulate the binary search, exactly like the editorial in E2.

        Your complexity is expected 1.75n at recursion depth 0, and then expected 0.25n * 3.5 due to left/right only having (expected) 0.25n candidates left as in editorial

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

          I am really sorry. I didn’t read E2 editorial correctly, my bad… Now it’s clear.

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

Is there any reason for disabling hacks in Div1A?

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

    To prevent hacks based on unordered sets. While I do not have any issues failing solutions that use unordered structures or equivalents, I would prefer participants to focus on solving the problems than hacking hashes.

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

    I think stress testing would break code though logically fine but poorly implemented, not required for div2b

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

Got WA on div1D because I did cout << a[0]; instead of cout << a[0] % mod; for $$$n=1$$$. I guess it would have been better to include this example in samples as $$$a_i$$$'s are usually less than the mod value :(

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

    I am sorry :( Actually we updated mod to $$$998244353$$$ recently to be consistent with 1G, and then forgot about this issue.

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

Div2D was a great problem!

»
8 months ago, hide # |
Rev. 2  
Vote: I like it +3 Vote: I do not like it

A (too complicated) forward DP solution for Div2D:

$$$dp(i) = \text{# of partial valid colorings up to row }i$$$
$$$dp(1) = \binom{n-2}{a_0-2}$$$

(Must color the two extreme cells)

Since we can only color cells up to the (n+1)/2 row, we can compute this DP up to n/2.

Define c_i as the number of cells we colored so far. Then we can divide our previous colorings into 3: if we already colored the 2 columns i and n-i+1, if we colored exactly one of them, and if we colored none. If we colored none, we must color them now to satisfy conditions 2 and 3, and similarly for the other cases. This gives rise to the following DP formulation:

$$$dp(i) = dp(i-1) \cdot ((\text{ratio both colored}) \cdot \binom{n-c_i}{a_i} + 2\cdot (\text{ratio one colored}) \cdot \binom{n-c_i-1}{a_i-1} + (\text{ratio none colored})\cdot \binom{n - c_i - 2}{a_i-2})$$$

Where the ratios mentioned are the fraction of previous colorings that colored the 2 columns i and n-i+1. Since we had some choice in coloring previously, we keep track of that number, which is basically

$$$d_i = \sum_{k=1}^i (a_k - 2)$$$

If we have n columns and we colored k of them, then the ratio where we colored both i and n-i+1 is

$$$\frac{\binom{n-2}{k-2}}{\binom{n}{k}} = \frac{k(k-1)}{n(n-1)}$$$

Similarly for one specific column colored and the other not colored, it is

$$$\frac{\binom{n-2}{k-1}}{\binom{n}{k}} = \frac{k(n-k)}{n(n-1)}$$$

Now just plug n = n — 2*i and k = d_i, and you have the DP formula.

340207087

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

Div.2B was that hard! But like all the problems ABCD :)

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

I hate 1E.

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

"A simple algorithm works, just make Alice take all items in S in increasing order, and when Alice wants to take some item but it is not the first remaining item according to her priority order, Bob takes items till it becomes first in her priority order."

Can anyone explain Div2E / Div1C editorial a bit easily, like how the above statement came ?

»
8 months ago, hide # |
Rev. 2  
Vote: I like it +141 Vote: I do not like it

Since editorials for D1F/G are not currently out, here are some somewhat handwavy outlines of my solutions:

F: WLOG, assume the graph is a tree (if it isn't, take a spanning tree and pretend the edges outside the spanning tree don't exist at the start). For the first query, take k = 3 and connect all pairs of vertices with distance 2. For the second query, take k = ceil(diam / 2) + 1, where diam is the diameter of the tree. We can construct paths with length ceil(diam / 2) between any two remaining vertices.

Indeed, by using the edges from the first query as needed, we can get from one vertex to another in any number of moves between ceil(dist(u, v) / 2) and diam and dist(u, v). If dist(u, v) < ceil(diam / 2), let d be the vertex on the diameter furthest from u. We can follow the path from u to v until it diverges from the path from u to d. Then, through a little casework, we can show that it's possible to visit every vertex between our current position and d and then return to the path to v. (If we don't need this many vertices, we can just not include d and the vertices closest to d on the path.) This lets us achieve any number of moves between dist(u, v) and the number of vertices in the union of the paths from u to d and u to v, which is at least dist(u, d). Thus, we can achieve any number of moves between ceil(dist(u, v) / 2) and dist(u, d). Since dist(u, v) <= diam and dist(u, d) >= ceil(diam / 2), this lets us achieve distance ceil(diam / 2), so we're done.

Here's my code. The complexity is O(n^3).

G: (very rough outline, I find this one fairly hard to explain...)

First, let's think about a subproblem that comes up throughout the task: how many sequences of a 0's and b 1's have longest nondecreasing subsequence (LIS) at least c? We can do complementary counting: for us to have no increasing subsequence of length c, at any point, the number of 0's used so far and the number of 1's remaining must be less than or equal to c. We can think about this as the number of grid paths from (0, 0) to (a, b) where at all points on the path, x + (b — y) < c. I think this subproblem is somewhat well-known in some circles (though it wasn't to me until I solved this task...). Assuming c >= max(a, b), this works out to (a + b) choose a — (a + b) choose c, so (a + b) choose c sequences have LIS at least c. (if c <= max(a, b), all (a + b) choose a sequences have LIS at least c.)

Now, let's get back to the main problem. To deal with the constraint that b is larger than a, iterate over the longest prefix shared between both strings. The next character of a must be 0, and the next character of b must be 1. This gives us O(n) (with n = x + y) possible prefixes of b, and we need to count the number of solutions with each prefix.

To reframe the LIS condition, we'll choose the minimum i such that B[0..i] has LIS k; then, we require that i exists (i.e. B itself must have LIS at least k) and that b[i+1..n] has LIS k. The easy case occurs when our prefix already has LIS at least k, so i has been predetermined. When this is the case, we can just ignore B[0..i], and we just need to ensure that the remainder of b has LIS at least k. This can be handled using the solution to the subproblem above.

The harder case is when our prefix has LIS less than k. In this case, let's iterate over i, i.e., we are iterating over the length of the shortest prefix with LIS k. (This is somewhat motivated by the solution to the subproblem, which largely depends on a+b.) For a fixed i, we can identify the minimum and maximum number of 0s in our prefix of length i, and for these two cases, we can directly compute the number of ways to choose our prefix (noting that we must subtract out cases where the prefix of length i-1 has LIS at least k) and multiply by the number of ways to choose our suffix with the remaining 0s and 1s.

Then, we can prove that the number of ways to choose our prefix is the same for all numbers of 0s strictly between the minimum and the maximum. The rough idea is that if we had more 0s than we needed to guarantee that our prefix has LIS k, the prefix of length i-1 would be guaranteed to have LIS k. Thus, we can have at most exactly the number of 0s needed to guarantee LIS k, which means any number of 0s less than the maximum won't guarantee LIS k. A similar argument applies to the 1s, meaning that if we have more than the minimum number of 0s, we aren't guaranteed to have LIS k. When we apply the subproblem solution, this ensures that we are in the (a + b) choose c case and not the (a + b) choose a case, and since a+b is constant, the whole expression is too.

From here, we can precompute the number of ways to choose a valid suffix with a 0's and b 1's with LIS at least k for all a and b, and using prefix sums, we can multiply the number of valid prefixes for each number of 0s times the number of valid suffixes over all possible numbers of 0s/1s for the suffix. Adding this to the minimum/maximum number of 0 case (which we compute separately as an edge case) gets us the answer for the given prefix of b, completing the solution. The complexity is O(n^2).

I doubt if my code will be helpful to read (though it does technically have a few comments...); if you'd like to take a look, it's at this link.

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

Problem D is good

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

I found problem B really challenging!

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

Can somebody explain me C.As i am unable to understand it from the editorial.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
  • In the Div2-C, for the test case 3 with
  • N = 4
  • {6149048, 26582657, 36124499, 43993239, 813829899, 860114890, 910238130, 913669539} -
  • for K = 2, we have been given 1737022233, as the output
  • but since there can at most be two persons simultaneously
  • then how can this not be considered
  • 1st person enters at point 1 then will leave at 8, 2nd person gets in at 2 and exits at 7?
  • which will give 1791175964, which is greater than the one as the answer given???
  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    what about the rest of the entrances and exits? you must also assign those to a person which will instantly violate the conditions of k = 2.

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

      Ok, the problem asks us to assign all the entrances and exists as the sensor detected all the 2*N points got it, got it My understanding of the problem was wrong since yesterday!!

      thanks!!

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

For 1C, I thought the condition should be $$$pox_x \lt pos_y$$$ where $$$pos_i$$$ is the position of item $$$i$$$ in array $$$b$$$, instead of $$$b_x$$$ < $$$b_y$$$

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

    Hey could you explain it in simple ways ?

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

      Denotes $$$posa_i$$$ is the position of the $$$i^{th}$$$ object in Alice's preferences, $$$posb_i$$$ is the position of the $$$i^{th}$$$ object in Bob's preferences. The condition for a valid subset of object that Alice could take is: suppose Bob takes the object $$$x$$$ and Alice takes the object $$$y$$$, and $$$posa_x \lt posa_y$$$, then $$$posb_x \lt posb_y$$$ must hold.

      For example $$$a = [1, 2, 3, 4]$$$ and $$$b = [2, 3, 4, 1]$$$ (it's actually the $$$7^{th}$$$ sample case). If Bob takes the object $$$1$$$, then Alice couldn't take the object $$$2$$$, $$$3$$$ or $$$4$$$ because in order to take the object $$$1$$$, Bob need to take the object $$$2$$$, $$$3$$$ and $$$4$$$ as well.

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

        progressed a bit ... my skill issue ;) btw what are the transitions you are using ?

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

    Agree

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

      Yeah same ... can you explain this transition part ? autolambda

       std::vector<i64> f(n + 1, -INF);
       f[0] = 0;
       for (int i = 0; i < n; ++i) {
           std::vector<i64> g(n + 1, -INF);
           for (int j = 0; j <= n; ++j) {
               if (r[i] + 1 > j) {
                   g[j] = std::max(g[j], f[j] + v[i]);
                   g[r[i] + 1] = std::max(g[r[i] + 1], f[j]);
               } else {
                   g[j] = std::max(g[j], f[j]);
               }
           }
           f = g;
       }
      
  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I saw your code for Div1C can you explain the dp like whats your dp state transition?? I am not able to fully understand editorial's dp solution

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

I have a general question about div2 e. During the contest, I found O(n^2) dp solution is quite naive.

$$$dp[i][j] = max(dp[i][j], dp[i - 1][j] + v[a[i]])$$$
$$$dp[i][j] = max(dp[i][j], dp[i][j - 1])$$$

That is, we have a row transition from condition (if b's j selected a[i], add 0) and always true column transition.

Although row transition is easily implemented by lazy propagation, I cannot solve this problem as I failed to implement column transition in O(logn).

I thought at each level i, we can keep the segment tree monotonic increasing. But the editioral says it is enough to change only one element. How can they think this simple trick easily? Just one thing for optimization always bothers me. Could you give some tip to resolve this situation? Most of the time, I can't think some minor point. Thank you in advance!

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

In the solution of Limited Edition Shop, it seems that there are some ambiguous points.

  1. $$$b_i$$$ should be the position of $$$i$$$ in orginal $$$b$$$, but there's no explanation.
  2. And in the transitions, the first $$$b_i$$$ should be $$$b_{i+1}$$$.
»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

div2 D such an amazing problem. Once you find the key point by observation(the graph), you can immediately solve this problem

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

I need a O(n*n) solution C++ code for div2 E, the Editotrial is not very clear to me QAQ......

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

Can someone explain the solution to E1 in more detail? I dont understand what the array waste stands for because waste contains the value which appear both in [tl, tr] and outside it. just implies waste contains all values xD

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

I hope I add the conclution of Div1 C.

First, make $$$a_i=i$$$ is right.But how does the array b change?

Obviously, if the number $$$x$$$ becomes $$$y$$$, then find $$$i$$$ such that $$$b_i=x$$$, and change $$$b_i$$$ to $$$y$$$, which can be achieved by $$$O(n)$$$.

Next, Let $$$x$$$ choose, $$$y$$$ choose not(actually also $$$a_x$$$ and $$$a_y$$$).We will have two situations:

  • $$$x \lt y$$$ : We find $$$j$$$,$$$k$$$ such that $$$b_j=x$$$ and $$$b_k=y$$$.If $$$k \lt j$$$, we can know that this is impossible(If we want choose $$$y$$$, then we must choose array a until $$$k$$$. But $$$x$$$ is also chosen.). Similarly, we can know that $$$k \gt j$$$ is possible.

  • $$$x \gt y$$$ : We can choose $$$y$$$ first, so is possible both $$$k \lt j$$$ or $$$k \gt j$$$.

So, we can modify array b like this: If $$$b_j=x$$$, then let $$$Newb_x=j$$$.

Lastly, the array Newb is the array b mentioned in the solution ! We can copy the values from Newb to b.

This can explain why "For all $$$x\in S$$$, $$$y\in S$$$, if $$$x \lt y$$$, then $$$b_x \lt b_y$$$".

This is my code(Only the part of change array b):

    for(int i=1;i<=n;i++)M[a[i]]=i;
    for(int i=1;i<=n;i++)c[i]=M[b[i]];//change the b[i] first
    for(int i=1;i<=n;i++)b[i]=c[i];
    for(int i=1;i<=n;i++)c[b[i]]=i;//find b[j]=x and change Newb[x] to j
    for(int i=1;i<=n;i++)b[i]=c[i];//copy the values

I hope it can help someone!

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

For Div.1 F, if we fix a root, we only need to consider two cases:

  • $$$\operatorname{dist}(u,v) \ge k$$$ : This is exactly the same as in the official editorial.

  • $$$\operatorname{dist}(u,v) \lt k$$$ :

The path can be split into three parts: $$$u \to \text{lca}$$$, then an “up-and-back” segment starting from the lca, and finally $$$\text{lca} \to v$$$.

Suppose that when going upward from the lca we eventually reach some node $$$x$$$. Let the nodes on this path be $$$p_0=\text{lca},p_1,\dots,p_{\text{len}}=x$$$.

We can then take all vertices with even (odd) indices in order, followed by all vertices with odd (even) indices in reverse order.

It can be checked that at least one of these two traversals correctly handles the cases $$$u=\text{lca}$$$ or $$$v=\text{lca}$$$.

Finally, it can be proven that if we try both endpoints of the diameter as the root, then at least one choice will always work.

340368161

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

TheScrasse , There seems to be some error in the editorial for Div2E , (Limited edition shop).

As per editorial, we assume, preference of items for Alice is $$$A_i = i$$$.

So, imagine array A (preference of Alice) = [1 , 2 , 3 , 4 , 5 , 6 , 7].

And.............. preference order for Bob B = [3 , 4 , 2 , 6, 1 , 7 , 5].


Now, imagine, I want to select a set S = { 1 , 4 , 6 } ( basically I want to select items 1 , 4 , and 6 ). S' = { 2 , 3 , 5 , 7 } ( items which are not selected by Alice, so must be selected by BOB).

Let's look at the condition given in the editorial...

For $$$x \notin S$$$, $$$y \in S$$$ , this condition must hold true $$$B_x \lt B_y$$$.

If we get all the pairs (x , y) where (x < y) and $$$x \in S'$$$ (or $$$x \notin S$$$ otherwise) and $$$y \in S$$$ , we have 5 pairs. (2 , 4) , (2 , 6) , (3 , 4) , (3 , 6) and (5 , 6).

for (2,4) , $$$B_2$$$ = 4 , $$$B_4$$$ = 6, So we can see $$$B_2$$$ < $$$B_4$$$.

for (2,6) , $$$B_2$$$ = 4 , $$$B_6$$$ = 7, So we can see $$$B_2$$$ < $$$B_6$$$.

for (3,4) , $$$B_3$$$ = 2 , $$$B_4$$$ = 6, So we can see $$$B_3$$$ < $$$B_4$$$.

for (3,6) , $$$B_3$$$ = 2 , $$$B_6$$$ = 7, So we can see $$$B_3$$$ < $$$B_6$$$.

for (5,6) , $$$B_3$$$ = 1 , $$$B_6$$$ = 7, So we can see $$$B_3$$$ < $$$B_6$$$.


Even after this condition, holds, we can never select the set of items { 1 , 4 , 6 } from order of preferences. Please help clarify this.

------------------------------------------------------------------ Update :

As per TheScrasse's reply, the editorial error has been fixed. this comment's content is outdated.

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

    I have not written the editorial for this problem. I think $$$b$$$ should be replaced with $$$b^{-1}$$$ (we care about positions of $$$x$$$ and $$$y$$$, not about the $$$x$$$-th and $$$y$$$-th element). Dominater069

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

In 2150D - Attraction Theory, I somewhat quickly arrived at counting the number of valid arrays of length $$$k$$$ as

$$$ c=[x^n] \left(\frac{x}{1-x}\right)^2 \left(\frac{x}{1-x^2}\right)^{k-2} = [x^{n-k}] \frac{1}{(1-x)^2} \frac{1}{(1-x^2)^{k-2}}, $$$

after which I spent embarrassingly much time on figuring out how to to reconcile things with $$$1-x$$$ and $$$1-x^2$$$ in the denominator. The intended solution ultimately does it by fixing the parity of the first and the last non-zero number, which I eventually also arrived to. After doing so, I also figured out that it is actually simple to count while still being in genfunc space:

$$$ c=[x^{n-k}] \frac{(1+x)^2}{(1+x)^2}\frac{1}{(1-x)^2} \frac{1}{(1-x^2)^{k-2}} = [x^{n-k}] \frac{(1+x)^2}{(1-x^2)^k}, $$$

which now has a uniform way to extract $$$x^{n-k}$$$, independently of the parity of border parts. Ultimately, it is still equivalent to what intended solution is doing, but I wanted to share the way to do in purely genfunc way. Then, the total sum over border elements can also be expressed as $$$s = [x^{n-k}] \frac{(1+x)^3}{(1-x^2)^{k+1}}$$$, and over inner elements as $$$\frac{c \cdot n-2s}{k-2}$$$.

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

I think there's a mistake in div2C editorial, starting from "Now we have to calculate the following terms:", I don't understand the rationale behind the formula, why there're multipliers up to k, aren't multipliers of +-1 next to a_i enough? There isn't an explanation how terms S1, S2 and S3 are combined to calculate the final answer. Solution (code) makes sense though, but it uses different approach, deriving k from k-2.

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

2151C — Incremental Stay is a shit and uncleared answer

»
12 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Sorry for necroposting. I got Div1E1 from a TLE bot on discord. I think the bound of $$$4n + 2 \lceil \log_2 n \rceil$$$ queries is very loose in most cases and thought it can be reduced down to something around $$$3.7 \cdot n + c$$$ where $$$c$$$ is some constant (for small cases). Next is a semi-formal proof.

Denote by $$$f(d, w)$$$ the number of queries used to find the value, given that we have $$$w$$$ "waste" and $$$d$$$ elements that could be the "lonely value". We can show that $$$f(d, w) = \frac{5}{3} d + w + f(\frac{d}{3}, \frac{d}{3}+\frac{w}{2})$$$.

We do that by noting that for a random permutation for a number that appears twice (the chance of it being only in the first half) = (the chance of it being only in the second half) = (the chance of it being in both halves) = $$$\frac{1}{3}$$$. If we query some number with one half and we get $$$0$$$ then we don't need to query the other half. Thus we have $$$\frac{1}{3} \cdot 1 + \frac{1}{3} \cdot 2 + \frac{1}{3} \cdot 2 = \frac{5}{3}$$$.

Similar to the editorial we query each of the wastes once so $$$+w$$$. Note that on average we get half of the wastes on each half (again, if we consider a random permuation of the indices instead of an interval) so we have $$$\frac{w}{2}$$$ waste in the next step. We also have $$$\frac{1}{3} \cdot d = \frac{d}{3}$$$ expected waste in the next step (from the values that appear in both halves). In total $$$\frac{d}{3} + \frac{w}{2}$$$ waste in the next step.

If we unfold the definition a bit and ignore the terms containing $$$d$$$, we will see a pattern (consider $$$\text{_}$$$ as a placeholder for $$$\text{constant} \cdot d$$$).

$$$f(d, w)= \text{_} + w + f(\text{_}, \text{_} + \frac{w}{2}) = \text{_} + w + \frac{w}{2} + f(\text{_}, \text{_} + \frac{w}{4}) = \text{_} + w + \frac{w}{2} + \frac{w}{4} + f(\text{_}, \text{_} + \frac{w}{8}) = \dots = \text{_} + w \cdot \displaystyle{\sum_{k=0}^\infty \left( \frac{1}{2} \right) ^ k} = \text{_} + 2w$$$

This leads us to $$$f(d, w) \leq \frac{5d}{3} + 2w + f(\frac{d}{3}, \frac{d}{3}) \leq \frac{5d}{3} + 2w + \frac{2d}{3} + f(\frac{d}{3}, 0) = \frac{7d}{3} + 2w + f(\frac{d}{3}, 0)$$$.

Let now $$$g(n) = \frac{7n}{3} + g(\frac{n}{3})$$$. Note that $$$g(n) = f(n, 0)$$$. We now get that $$$g(n) \leq \frac{7n}{3} \cdot \displaystyle{ \sum_{k=0}^\infty \left( \frac{1}{3} \right)^k } = \frac{7n}{3} \cdot \frac{3}{2} = \frac{7}{2} n$$$. Thus $$$f(n, 0) \leq \frac{7}{2}n$$$.

This proof is not very formal, there are missing expected values and stuff. I also tested it locally with random tests and the maximum factor is around $$$3.7$$$ for large values of $$$n$$$. Sadly, for small values it fails quite badly, sometimes reaching and even slightly exceeding $$$4$$$ (although a constant like $$$40$$$ or something might fix this still)

»
9 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

can anyone explain, in Div1B, for the first test case, why the following grid is not valid?

10001 10001 00100 00000 00000

here 1 represents black and 0 white.

this grid satisfies all the given conditions still they haven't considered it as a valid solution for test case 1