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

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

Below is a timeline of the changes made to the round from start to finish. I hope this can depict what setting a contest is actually like for aspiring problemsetters. Please give me feedback about this in the comments. What else about the round would you like to know? Was this helpful?

Round Timeline

Please check out this amazing animated video tutorial by one of our beloved testers redpanda!!!

2030A - A Gift From Orangutan

Problem Credits: Proof_by_QED
Analysis: Proof_by_QED

Solution
Code (Python)

2030B - Minimise Oneness

Problem Credits: Proof_by_QED
Analysis: Proof_by_QED

Solution
Code (C++)

2030C - A TRUE Battle

Problem Credits: Proof_by_QED
Analysis: Proof_by_QED

Solution
Code (C++)

2030D - QED's Favorite Permutation

Problem Credits: Proof_by_QED, cry
Analysis: cry

Solution
Code (C++)

2030E - MEXimize the Score

Problem Credits: Proof_by_QED, cry, satyam343
Analysis: cry

Solution
Code (C++)

2030F - Orangutan Approved Subarrays

Problem Credits: Proof_by_QED, satyam343
Analysis: Proof_by_QED

Solution
Code (C++)

2030G1 - The Destruction of the Universe (Easy Version) and 2030G2 - The Destruction of the Universe (Hard Version)

Problem Credits: Proof_by_QED, satyam343
Analysis: satyam343

Solution (Easy Version)
Solution (Hard Version)
G1 Code (C++)
G2 Code (C++)
Разбор задач Codeforces Round 979 (Div. 2)
  • Проголосовать: нравится
  • +206
  • Проголосовать: не нравится

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

Thanks to the authors for the interesting tasks :D

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

Sad for F... I did every observations required to solve problem but i could not combine it :(

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

Fast solution Updated! Thanks

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

StringForces

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

The difficulty of problem F may be a little bit low.

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

D felt like I needed a data structure I don't know of. Any ideas?

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

    I don't get the editorial too much. Please look at my submission, it is more straightforward. All you need to so is make an array with the max from the front and min from the back. For the array, 1 4 2 5 3, mx is [1,4,4,5,5] and mn is [1,2,2,3,3]. For any index such that s[i] == 'L' && s[i+1] == 'R' it is enough the check if max[i] <= mn[i+1], if so, the index is not a problem. Store the number of problems. It is not necessary to store the indices. When you change an index to L from R or vice Versa, check the indexes around it to see if the bad count would be affected. If bad==0, SAY yes else say no. Submission: https://codeforces.me/contest/2030/submission/286799491

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

      I don't see why you use both a max prefix and a min suffix.
      Build first a max prefix array $$$pref$$$. As you said, you can iterate over $$$i$$$ and check if $$$s[i] == 'L' && s[i+1] == 'R'$$$. It is a potential block, since it will prevent any element with index below or equal to $$$i$$$ to go to a position with index over $$$i$$$ (and reciproquely).
      But it is only a problem if this prevents us to sort the array. This isn't a problem if all elements below index $$$i$$$ can be sorted independantely, i.e. there are values from $$$1$$$ to $$$i$$$. In this case, $$$pref[i] == i$$$. If $$$pref[i] \gt i$$$, then the block is active, and we count one conflict.

      Count the number of initial conflicts, and for each query, you can check locally if this resolves a conflict or create one.

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

        Ok i was confused at first but i think your solution relies on the fact that it is a permutation. To be honest, I completely missed the fact that it was a permutation hence my general solution, still I think my solution is easier to think about and also more general. I assume in your solution if pref[i]<i you do nothing since the conflict would be counted before? But the fact that I even have to think about that makes my solution a little better I think.

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

      Elegant solution.

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

    you can see that for any substring of S, that doesnt contain the substring LR in itself, that substring is sortable. thus it is sufficient to check whether the substrings of LR partition the string into parts that, when sorted make the entire array sorted. you can do that by constructing intervals where l=min(pos[i],i) and r=max(pos[i],i). what this means essentially is just an interval that starts where the number is and where its supposed to be(or vice versa). then another observation is that if 2 intervals intersect, then you can merge them and they can be considered one interval. next for each query you can just check whether this changes the amount of LRs in the entire string and if an LR dissapears then check if it previously "ruined" the array, or if an LR appears, check if the new LR "ruins" the array. sorry if this is unclear, but ask any questions, id be glad to explain further.

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

      i did something similar , to check if segment is sortable or no

      compare its sum [ l ,r ] it should be equal to [ l, r ] when the array is sorted ( we created a sorted permutation from( 1 , n )) to compare the segments

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

My solution to D is in $$$O(n + q)$$$, using prefix sums. https://codeforces.me/contest/2030/submission/286798401

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

f similar to https://open.kattis.com/problems/wiknow although still couldn't solve it :(

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

Can we just appreciate the Round Timeline :)

It was really insightful as to how problems are actually made and well the coordination skills of satyam343

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

can anyone help me find mistake in my code for D.My logic was same.. here is my submission 286813972

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

Another solution for D is to precalculate all intervals in the array that are permutations of their indices and process the queries with a segment tree. You can store the array intervals' ends in a set and, for each bad index LR in the string, you can consider it as two intervals: one ends at L and the other starts at R. For the permutation to be sortable, every string interval's end must also be an end in the set of indices we calculated for an array.

So the segment tree on the LR string can store nodes that contains the leftmost character on the range, the rightmost character on the range, and whether or not all the endings in the range are also in the set of array indices. If they are, then we are able to sort that range. The tree can be updated in $$$O(\log{n})$$$, and the answer is the root of the segment tree.

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

When you have seen the problem statement somewhere else...

(Of course, it's okay since the problem requirement is totally different)

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

Alternate solution to problem C: Notice that the substring "010" is bad, we just need to check if there is a '1' that is not inside "010" then the answer is YES, otherwise NO

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

    Can u please elaborate I had similar approach so I have check if 010 in string or 010 in start or 101 in end but got wa

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

      Basically, the idea for substring "010" is there are 2 options to choose from: "01" or "10".

      We know that the "and" operations will be evaluated first, so even if Alice moves before Bob, no matter which she chooses to do the "or" operation on, Bob can "counter-attack" that move by choosing the other one. Which means the substring "010" will always become "000".

      For any other cases where there is a '1', because Alice moves first, Alice can pair that '1' with whatever other digit that is next to it to do the "or" operation and get the result of '1'. Bob cannot "counter-attack" it, because he can not make that '1' become '0' before Alice if the substring is not "010", so Alice will have at least one '1' at the end. She will win.

      It's just my intuition and some deducing while solving the problem, hope it helps!

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

Nice contest! I just fumbled in D problem.

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

thanks for fast editorial

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

Great contest, and thank you for the fast editorial ! I was so close to finish D ... Next time I will

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

I think ignoring the fact that D is a permutation leads to a easier solution. Is this bad writing(still a great problem!) or was this intentional by the writers, just curious.

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

I can't get the proof of the given observation for problem E in the tutorial. Can anyone please explain it?

Let b = {0, 0, 1, 1}

f0 = 2, f1 = 2. Depending on the observation the score should be 4. But I can't get more than 3, doesn't matter how I perform the partition.

It is possible that I compiled the problem wrong. Hoping your help.

Thanks in advance.

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

https://codeforces.me/contest/2030/submission/286828473

I thought a little different for problem D but idk where it's going wrong. The basic intuition is the string should be of type R*L* (RRR...LLL). So, I stored the indices of L and R in two separate sets. If highest(SetR)<lowest(SetL) is true, answer to that query will be True. And if the array starts in correct order (1,2,3..) I neglect those indices, same for ending (..n-2,n-1,n). I'm unable to understand why this approach isn't working?

Got the error, I'm dumb

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

cool contest, maybe C was a bit too easy though?

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

How I solved A, B, C during the contest and D shortly after?
I would like any constructive feedback.

2030A - A Gift From Orangutan

My Thinking

2030B - Minimise Oneness

My Thinking

2030C - A TRUE Battle

My Thinking

2030D - QED's Favorite Permutation

How did I solve it ?
»
23 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

First 3 questions felt like speedForces but D was good, i could not do it. ps: thanks for the fast editorial!!

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

JUST SHARING MY THOUGHTS ON E


I felt E was quite hard enough. Instead of finding sum of all subsequences Mex, even if they had asked just number of different subsequences, such that their Mex is some given number(x)... that would have been good fit (IMO)

May be this could have been 2 part question,

1) first part: you have to compute number of ways,

2) second part: you have to compute the sum

cc : cry

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

Just reached master, thank you authors for these lovely problems.

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

My solution to D, using ordered sets in C++. I really liked the way this problem looked like a standard div3E/F exercise on data structures!

P. S. Back to blue with this contest! ^~^

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

Problem E

“Suppose we partition the elements of an array b into any number k of non-empty multisets S1,S2,…,Sk”

What does this mean? Can I partition [2,0,1,0,3] into [2,1,0,3] and [0]?

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

Another proof for problem B:

We can express $$$g(t)$$$ as the total number of subsequences, excluding those containing only zeros:

$$$g(t) = (2^n - 1) - (2^z - 1)$$$

where z is the number of zeros. So the absolute difference becomes:

$$$|g(t) - f(t)| = |(2^n - 1) - (2^z - 1) - (2^z - 1)| = |2^n - 2^{z+1} + 1|$$$

As we aim for the smallest difference, let's assume it's 0:

$$$|2^n - 2^{z+1} + 1| = 0$$$
$$$2^n + 1 = 2^{z+1}$$$
$$$z = \log_2(2^n + 1) - 1$$$

as we can see, z can’t be an integer in this case.

Let's check for 1:

$$$|g(t) - f(t)| = 1$$$
$$$|2^n - 2^{z+1} + 1| = 1$$$
$$$2^n = 2^{z+1}$$$
$$$z = n - 1$$$

Thus, constructing a string with n - 1 zeros is the best option.

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

Problem D can be done using xor hashing as well in O(n).

286885996

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

Those who see my profile picture are handsome mans,haha

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

Can someone explain why doing 2(fi+1+⋯+fn−1) to find the dp score in problem E does not overcount? Like we would count all subsequences longer which we will just consider later? Also wouldn't each dp overcount as well? Like every dp[2][2] is also a dp[1][2] so we would overcount by a lot?

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

F can be solved using XOR hashing and Fenwick tree: submission link

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

Problem D

1 3 5 2 4

L L R L L

if i swap 5,2 ,then 5,4 ,then 3,2 , i can sort it ,but answer is NO

why?

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

Alternate solution for problem E:

We're going to calculate, for each value $$$i$$$ from $$$0$$$ to $$$n-1$$$, its contribution to the sum.

Let $$$f_i$$$ be the number of occurrences of value $$$i$$$. Following from the same observation as the editorial, value $$$i$$$ contributes $$$min(f_0, f_1, f_2 ... f_i)$$$ to the sum if the array is fixed. For short, let the result of that computation in the original array be $$$M_i$$$ and, in some subset, $$$m_i$$$. We want to compute for each value $$$i$$$ the sum of $$$m_i$$$ for every subset of $$$a$$$.

For the contribution of value $$$i$$$, the result of $$$m_i$$$ in each subset is not affected by the values greater than $$$i$$$ we choose. Let $$$S_i = \sum_{j=i+1}^{n-1}f_j$$$, that is, the sum of occurrences of values greater than $$$i$$$. We can compute the sum of $$$m_i$$$ for subsets less than $$$i$$$ and multiply that by $$$2^{S_i}$$$.

To compute the sum of $$$m_i$$$ over all subsets considering values less than $$$i$$$, we're going to calculate, for each possible value $$$x$$$ up to $$$M_i$$$, how many subsets exist such that $$$m_i = x$$$. Let $$$F(j,x) = \sum_{k=x}^{f_j}{{f_j}\choose{k}}$$$, that is, the amount of ways to choose at least $$$x$$$ elements from the amount of occurrences of $$$j$$$. The amount of subsets of values less than $$$i$$$ where $$$m_i = x$$$ is given by $$$G(i,x) = (\prod_{j=0}^iF(j,x)) - (\prod_{j=0}^iF(j,x+1))$$$, that is, the amount of subsets where the amount of occurrences of every value up to $$$i$$$ is at least $$$x$$$ minus the amount of subsets where the amount of occurrences of every value up to $$$i$$$ is at least $$$x+1$$$. From that, we know for each $$$x$$$ its contribution to the sum.

The answer to the problem can therefore be obtained by the following sum:

$$$\large{\sum_{i=0}^{n-1}2^{S_i}\cdot\sum_{x=1}^{M_i}{x \cdot G(i,x)}}$$$

These two outer sums amount to $$$\mathcal{O}(\sum_{i=0}^{n-1}f_i) = \mathcal{O}(n)$$$. However, the computation of $$$G(i,x)$$$ seems to make the overall complexity $$$\mathcal{O}(n^3)$$$ because of the computation of $$$F$$$ and $$$G$$$.

How can we compute G faster?
How can we compute F faster?

From all of this, we can calculate the answer to the problem in $$$\mathcal{O}(n)$$$ total.

Code: 288412616

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

thanks to author of solution of problem c which nicely explaned

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

in first test case 5 3 1 4 2 5 3 RLRLL 2 4 3

in q=3

we have-

R L L L L

1 4 2 5 3

now we can apply operations i this formm---

1 4 2 3 5 1 4 3 2 5 1 3 4 2 5 1 3 2 4 5 1 2 3 4 5

thus sorted then why NO??

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

I suggest that the meaning of "partition" in Problem E should be clarified. This word is very likely to cause misunderstanding and I wasted quite a lot of time because of it...

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

Problem F also we can solve with Merge Sort Tree and the same idea of nexts.