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

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

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: vgoofficial
Analysis: vgoofficial

Solution
Code (Python)

2030B - Minimise Oneness

Problem Credits: vgoofficial
Analysis: vgoofficial

Solution
Code (C++)

2030C - A TRUE Battle

Problem Credits: vgoofficial
Analysis: vgoofficial

Solution
Code (C++)

2030D - QED's Favorite Permutation

Problem Credits: vgoofficial, cry
Analysis: cry

Solution
Code (C++)

2030E - MEXimize the Score

Problem Credits: vgoofficial, cry, satyam343
Analysis: cry

Solution
Code (C++)

2030F - Orangutan Approved Subarrays

Problem Credits: vgoofficial, satyam343
Analysis: vgoofficial

Solution
Code (C++)

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

Problem Credits: vgoofficial, satyam343
Analysis: satyam343

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

»
5 часов назад, # |
Rev. 2   Проголосовать: нравится +27 Проголосовать: не нравится

Thanks to the authors for the interesting tasks :D

»
5 часов назад, # |
Rev. 2   Проголосовать: нравится +2 Проголосовать: не нравится

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

»
5 часов назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Fast solution Updated! Thanks

»
5 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

StringForces

»
5 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can you please not frozen the standings?

I want to read others' submission for problem G NOW as the editorial is not published yet.

  • »
    »
    4 часа назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    System Testing may have begun, it gets completed in ~1 hour or lesser depending on the pretests accepted submissions.

    Though submissions will be available now, you can use the status tab as soon as a contest finishes to view and filter other submissions.

»
5 часов назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

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

»
5 часов назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

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

  • »
    »
    5 часов назад, # ^ |
    Rev. 4   Проголосовать: нравится +1 Проголосовать: не нравится

    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.net/contest/2030/submission/286799491

    • »
      »
      »
      4 часа назад, # ^ |
        Проголосовать: нравится 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] > 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.

      • »
        »
        »
        »
        4 часа назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        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.

        • »
          »
          »
          »
          »
          4 часа назад, # ^ |
            Проголосовать: нравится 0 Проголосовать: не нравится

          Yeah you're right, this works since it is a permutation. In this case, $$$pref[i]$$$ is always greater or equal to $$$i$$$

      • »
        »
        »
        »
        4 часа назад, # ^ |
        Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

        This is a nice observation that makes the code more simple. If pref[i] > i, it means there's a number missing from 1 to $$$i$$$. Then you can use the prefix array to do all necessary checks while updating the input string. I wish I'd have thought of it during the contest.

  • »
    »
    2 часа назад, # ^ |
      Проголосовать: нравится 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.

    • »
      »
      »
      111 минут назад, # ^ |
        Проголосовать: нравится +1 Проголосовать: не нравится

      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

»
5 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Thanks for the contest and fast editorials ༼ つ ◕_◕ ༽つ

»
5 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
5 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
5 часов назад, # |
  Проголосовать: нравится +12 Проголосовать: не нравится

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

»
5 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Started happily with A and B. C crashed and burnt for me. couldn't figure out :(.

»
5 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
5 часов назад, # |
  Проголосовать: нравится +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.

  • »
    »
    4 часа назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    This is probably the most leetcode submission idea. I had something similar. Takes forever to implement though.

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

    could u explain this part more ?

    and whether or not all the endings in the range are also in the set of array indices

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

    u dont need segment tree bcz ur check function ```if (left.right == 'L' && right.left == 'R') { if (ends.count(mid)) { seg_tree[node — 1] = {left.left, right.right, true}; } else { seg_tree[node — 1] = {left.left, right.right, false}; } } else { seg_tree[node — 1] = {left.left, right.right, true}; }

    ``` u are only checking when u are the next node from the leaf of segment tree ,

    u can check it manually on array ( 2 adjacent indicies who = "LR" )

»
5 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

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

  • »
    »
    5 часов назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Well well well, the author looks familiar as well... :)

    • »
      »
      »
      5 часов назад, # ^ |
        Проголосовать: нравится +9 Проголосовать: не нравится

      our supreme problemsetter went ahead and took the chance to steal the statement from HIMSELF

»
5 часов назад, # |
  Проголосовать: нравится 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

  • »
    »
    5 часов назад, # ^ |
      Проголосовать: нравится 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

    • »
      »
      »
      4 часа назад, # ^ |
        Проголосовать: нравится 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!

»
5 часов назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

let f(t) be the number of non-empty subsequences† of t that contain only 0

should be 0's

»
5 часов назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

Nice contest! I just fumbled in D problem.

»
4 часа назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

thanks for fast editorial

»
4 часа назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
4 часа назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I wish I could have cracked B this time thought it was a nice experience as it was my first contest solved A and almost solved B and C will improve!

»
4 часа назад, # |
  Проголосовать: нравится 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.

»
4 часа назад, # |
  Проголосовать: нравится +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.

  • »
    »
    4 часа назад, # ^ |
      Проголосовать: нравится +2 Проголосовать: не нравится

    Partition into multisets {0, 1} and {0, 1}, score is 2 + 2 = 4.

    • »
      »
      »
      4 часа назад, # ^ |
      Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

      I just got it as soon as I posted the comment. My bad. It also fined me half of an hour during contest.

      Thanks for your reply.

  • »
    »
    4 часа назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Wait. I think I get it. I am petitioning the array into subsegments during the whole contest. But It can be partitioned into subsequences.

»
3 часа назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

https://codeforces.net/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

»
3 часа назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
3 часа назад, # |
Rev. 5   Проголосовать: нравится +4 Проголосовать: не нравится

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 ?
»
3 часа назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
2 часа назад, # |
  Проголосовать: нравится 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

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

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

»
107 минут назад, # |
Rev. 4   Проголосовать: нравится +1 Проголосовать: не нравится

Could somebody please tell me why is my code for D incorrect at 4th test case? What am I missing?

#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define fr(a, b) for (ll i = a; i < b; i++)
#define fa(a, b) for (ll i = a; i >= b; i--)

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tC;
    cin >> tC;
    while (tC--)
    {
        int n, q;
        cin >> n >> q;
        int a[n];
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        string s;
        cin >> s;
        while (q--)
        {
            int index;
            cin >> index;
            index--;
            if (s[index] == 'R')
                s[index] = 'L';
            else
                s[index] = 'R';
            int ans = 1;
            int k=0;
            for (int i = 0; i <= n - 1; i++)
            { 
                if (a[i] > i + 1)
                {
                    k= max(k,a[i] - 1);
                    while (i < k && s[i] == 'R')
                    {
                        i++;
                        k = max(k, a[i] - 1);
                    }
                    if(i ==k)
                    i--;
                    else if (i < k)
                    {
                        while (i <= k)
                        {
                            if (s[i] == 'R')
                            {
                                ans = 0;
                                break;
                            }
                            i++;
                            if(i <=k)
                            k = max(k, a[i] - 1);
                        }
                    }
                }
            }
            if (ans)
            {   
                int k=1e7;
                for (int i = n-1; i >=0; i--)
                {
                    if (a[i] < i + 1)
                    {
                        k = min(a[i] - 1,k);
                        while (i > k && s[i] == 'L')
                        {
                            k = min(k, a[i] - 1);
                            i--;
                        }
                        if(i == k){
                            i++;
                        }
                        else if (i > k)
                        {
                            while (i >= k)
                            {
                                if (s[i] == 'L')
                                {
                                    ans = 0;
                                    break;
                                }
                                i--;
                                if(i>=k)
                                k = min(k, a[i] - 1);
                            }
                        }
                    }
                }
            }
            if (ans)
            {
                cout << "YES" << endl;
            }
            else
                cout << "NO" << endl;
        }
    }
    return 0;
}
»
86 минут назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

while exploring the jungle, you come across a rare orangutan wearing a bow tie and he gifted you an array

Wow thanks Asshole

»
79 минут назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I don't know if it's because of my rank but I think you need some work on the statements like problem C for example

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

    I think C was pretty clear, but that clarification for B was important. I personally believe it should've been included in the statement

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

      I was think that you must move from left to right I didn't get that it isn't work like that but the problem was very easy after that

»
77 минут назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Love the round timeline! It's really fascinating to learn how contests are prepared, and how much time and efforts it takes. Thank you :)