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

Автор sevlll777, история, 8 месяцев назад, По-русски

Привет Codeforces! В 07.09.2023 17:35 (Московское время) начнётся Codeforces Round 895 (Div. 3). В этом раунде будет 7 задач, которые подобраны по сложности так, чтобы составить интересное соревнование для участников с рейтингами до 1600. Однако все желающие, чей рейтинг 1600 и выше могут зарегистрироваться на раунд вне конкурса.

Раунд пройдет по правилам образовательных раундов. Таким образом, во время раунда задачи будут тестироваться на предварительных тестах, а после раунда будет 12-ти часовая фаза открытых взломов. Мы постарались сделать приличные тесты — так же как и вы, мы будем расстроены, если у многих будут падать решения после окончания контеста.

Вам будет предложено 7 задач и 2 часа 15 минут на их решение.

Штраф за неверную попытку в этом раунде будет равняться 10 минутам.

Напоминаем, что в таблицу официальных результатов попадут только достоверные участники третьего дивизиона. Как написано по ссылке — это вынужденная мера для борьбы с неспортивным поведением. Для квалификации в качестве достоверного участника третьего дивизиона надо:

  • принять участие не менее чем в пяти рейтинговых раундах (и решить в каждом из них хотя бы одну задачу)
  • не иметь в рейтинге точку 1900 или выше.

Независимо от того являетесь вы достоверными участниками третьего дивизиона или нет, если ваш рейтинг менее 1600, то раунд для вас будет рейтинговым.

Задачи были придуманы и подготовлены: Alexdat2000, FairyWinx, sevlll777, Vladosiya, и MikeMirzayanov.

Также большое спасибо:

  1. Vladosiya за прекрасную координацию раунда, и помощь в подготовке и балансировке набора задач.
  2. MikeMirzayanov за платформы Polygon и Codeforces.
  3. Ormlis за чёрно-красное тестирование раунда.
  4. zwezdinv, BledDest за красное тестирование раунда.
  5. Sokol080808, diskoteka, Sweezy, vladmart, Kniaz, Tima, Riblji_Keksic, 74TrAkToR, pavlekn за жёлтое тестирование раунда.
  6. moonpie24, gs20036, Kolychestiy за фиолетовое тестирование раунда.
  7. martin0327, tnaito, no_mind, Pa_sha, SashaT9, ctraxxd, ezdp, BF_OF_Priety за синее тестирование раунда.
  8. NerfThis, _SADIEM_, YudoTLE, sayed_4 за циановое тестирование раунда.

Всем удачи!

UPD: Разбор

  • Проголосовать: нравится
  • +288
  • Проголосовать: не нравится

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

I enjoyed the problem set during testing, good luck to all the participants!

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

Me getting +100 tomorrow after solving 5 problems

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

Problems' quality are just great and fun to be solved UwU

For all participants, May the odds be ever in ur favor❤️

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

As a tester , I can assure that this is the most balanced div-3 problemset I have ever faced and I recommend to read every problem

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

As a tester, I hope you will enjoy this incredible contest

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

Div. 3 rounds are my favorite. Good luck to all participants (and me)!

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

I think the problems are nice. Good luck to participants!

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

Good luck!

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

Good luck!

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

Big chance to reach green tomorrow

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

I hope I don't get hacked again

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

I hope I will enjoy the problems during the contest(^ω^)

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

I will try to solve all :>

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

As a tester I recommend reading all problems. All problems are really fun, good luck!

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

OMG , Janmashtami round

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

Hope to become Cyan in this contest :)

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

As a tester, hope you all to enjoy with the round :")

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

Can I get a 10 minute head start on this contest so I have a better chance to get specialist?

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

Good luck!

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

MY first unrated Div 3.

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

Once upon a time when Division3 = Vovuh

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

Hope to reach 1000 in this contest.

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

Hope I can solve 4-5 problems in the round

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

This is no longer rated for me.. Weird bittersweet feeling

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

smile

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

I'm determined to reach green in this round.

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

I am excited to participate in this contest. Good luck for all participants.

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

i dont understand how the rating system works. i Have not given 5 contest but my rating is lower than 1600 so i am not trusted but i can give contest and i will be rated? how does this work

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

hope to reach at least 1000! :)

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

expecting high quality of problems from Vladosiya as usual

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

Last time, my sister was angry during contest and this time Shri Lord Krishna will be :(

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

Good luck to everyone! I really hope that I get specialist back

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

I am gonna solve 2 problems in this contest

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

Why My contest habit is bad ?

Why can't contest be like Atocoder which is at 5:30 IST ?

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

mathforces

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

very balanced contest, loved it.

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

$$$t$$$ test cases forces

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

problem C is such a troll problem

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

NumberTheory-Forces

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

Had to copy paste

int t; cin >> t;
while (t--)

so many times during this contest. These questions were easy but i just couldn't figure out the small details :/

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

Any hint on how to solve problem E?

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

    Segment Tree

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

      Ohh ok THx, I was trying to solve this using difference array but was getting TLE

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

        I thought about using prefix sums but it would have taken some time to figure out the correct way for it so instead I used segment trees with lazy propagation which was pretty obvious. Still messed up the code and got 2 WA's

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

          It is quite easy. Just observe that if you have the XOR of the ones in the entire array and a XOR prefix array. Then when a query asks you to invert [l,r], that just means you set ones^=prefix[l,r], zeros^=prefix[l,r].

          Because every element is its own inverse over XOR. So when you remove all the 1 elements, thats the same as adding all the 1 elements. So inverting [l,r] is just adding the XOR of that entire array to ones and zeros XOR.

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

            Got it thnx. I first thought about 2 separate prefix xor array's one for ones and other for zeros complicating it that's why i aborted the idea and went with segment trees.

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

              how u implemented segment tree, can u explain?

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

                222304569

                I stored the xor of 0's in the range and xor of all 1's in the range and for lazy updates whenever i find a range that is inside the needed range just swap the values and set its children to do lazy updates whenever they are visited. And before accessing any range check if it has to be updated or not, if yes then update its value and set its children to do lazy update whenever they are visited.

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

                  cool thanks and i presume st[node].second is xor of all values in range right?

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

                  ya insted of storing xor of all zeros i used xor of all values since you can get xor of zeros just by doing xor1 ^ xorall

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

          i think there is no need of lazy propagation just segment tree works fine but my code is giving wrong answer on first test case its giving 3 2 6 7 0 instead of 3 2 6 7 7 , can some one help me with this.My submission link thanks in advance

          • »
            »
            »
            »
            »
            »
            8 месяцев назад, # ^ |
              Проголосовать: нравится +10 Проголосовать: не нравится
            if (lx >= a && rx <= b) {
                    swap(zero[k], one[k]);
                    return;
                }
            

            I think you cannot do just that since you are not removing outdated nodes below which you update from afterwards... You should tell your child nodes to swap as well which is basically a lazy propagation.

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

            If you swap the values for a node it's children's values also have to be swapped

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

      It can be solved with sqrt decomposition too :)222263672

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

      It could be solved by using prefix Xor (same idea with prefix sum)

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

    Just maintain the XOR of numbers with s[i]=='0', and XOR of numbers with s[i]=='1'. Then for each query of type 1, XOR the above 2 numbers with a special number based on the L and R given.

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

great contest!

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

How to solve E without using segment tree?

  • »
    »
    8 месяцев назад, # ^ |
    Rev. 3   Проголосовать: нравится +1 Проголосовать: не нравится

    We can use a prefix XOR to get range XOR efficiently. Let us define variables g0 and g1, which is the initial XOR of all the 0s and 1s. Then we set up our prefix XOR array.

    Notice that when doing 1 l r, we can just take the xor value and then g0 ^= res and g1 ^= res. This works because when we flip the bits, we flip the whole range of xor for those variables as well

    query 2 is just printing g0 or g1.

    Submission: https://codeforces.com/contest/1872/submission/222311808

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

    You can use prefix Xor 222276789

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

Problem B explanation was not good, almost wasted 1.5 hours to understand

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

Enjoyed contest after long time.Thank you.Did not perform any good.But enjoyed it.

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

How to solve G? If we have at least >= 20 non-unit elements, the answer is obvious. However, i still don't understand how to find the answer if there are only k < 20 non-units, even in O(2^k) or something like this...

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

    Two pointer / sliding window to test all segments with exactly k non-unit elements for each value of k.

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

    I did brute force in O(k^2) with all indexes l, r (less than 30 indexes in my solution)

    Find the maximum sum(1,l-1) + sum(r+1, n) + product(l, r) and print l, r.

    Sum and product can be calculated with prefix sum and prefix product

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

      But what if the product is really huge, e.g. you have 30 indexes with value = 1e9?

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

        I just print the index of the first and last number greater than 1 in this case

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

          Suprisingly, I thought about everything i heard from you, but still was not able to build the solution. Clearly, something went wrong... Thanks for explanation :)

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

            same here.I thought of all the things but still can't able to get to the proper solution/code.

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

Was it just me who wasted 5 min on problem A because of this:

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

How my brain processed Problem C:

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

great

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

Thanks for the contest. It was really amazing.

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

I really liked the problemset

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

it feels so good after solving E.

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

Amazing contest! Problems were nice and fun to solve. Thanks to Alexdat2000 FairyWinx sevlll777 Vladosiya for the round.

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

Can anyone tell me where my code for problem C is failing? Link to my submission

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

Problem D is just to find number of indices which is divisible by both x and y.

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

.

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

    in the findsum function, if total is odd total/2 would give incorrect value, so divide by 2 only after calculating the whole numerator

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

amazing contest!! I feel G is much more easier than F. Maybe its just my skill issue on graph problem. haha

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

    How did you solve G?

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

      tbh, i think my solution is not correct, however it got AC, so here how its work.

      you can simplify the problem into "Find subsegment with biggest difference of its sum and product"

      if the multiplication of the element in the array is very large, lets say its over 1e9, then you always can choose segment (l, r), where l is leftmost not 1 element, and r is rightmost not 1 element.

      if the multiplication of the element in the array is not very large, then it only has very few not 1 element (at most 60 element maybe, and the rest is "1", and you can ignore the "1" for product). Then you can do some bruteforce work to find which segment is most optimal

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

        I think that works, thanks!

        For F I copy pasted strongly connected components code. Now all the nodes are split into their own scc, we can find the minimum cost node in the component, then we need to move in that cycle and end at that node that we picked.

        Submission: https://codeforces.com/contest/1872/submission/222333264

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

          wow i really didn't think of that. Thanks!

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

          My intuition for F was something like this :

          It would be beneficial for us to sell animals which isn't feared by anyone first (because that animal must be afraid) so start sell the animal with 0 in-degree. For this we can use topological sort

          Now we left eith the groups of cycle. For each group, we can see that all animals will be sold for $$$2c$$$ price except the last one. That's why to maximize the sum, we just need to find which animal is the cheapest in the cycle and sold it last

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

          I used the topological sorting after removing an edge at the optimal point to break cycles

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

Problem 3,, Any Valid answer can't accepted?

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

I spend almost one hour in finding the number of indices which is multiple of both a and b.

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

Amazing set of problems & a great contest!

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

Have someone did F with path compression ?

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

    What do you mean by path compression? The DSU trick?

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

      Yup

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

        In that case, I did solve it with path compression but only because I frequently use DSU to track connected components. It isn't really necessary (but if you want to use DSU it's absolutely necessary).

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

Quick Editorial:


Problem A

Problem B

Problem C

Problem D

Problem E

Problem F

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

    How to come up with the formula for problem A?

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

      WLOG (Without Loss of Generality) let us assume $$$a \leq b$$$, then it is optimal to pour $$$c$$$ from $$$b$$$ to $$$a$$$.

      We can see that the differences of $$$b$$$ and $$$a$$$ decrease by $$$2x$$$ if we try to pour $$$x$$$ from $$$b$$$ to $$$a$$$.

      We need to make the differences equal to $$$0$$$, then the intuitive way to find the formula is by using ceiling from the differences of $$$a$$$ and $$$b$$$ divided by $$$2c$$$

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

        Ummm I still couldn't understand how you reached that formula >.< . Ummm can you explain why did we go about dividing 2c ?

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

          In 1 operation, you are not just removing c from the larger vessel but also adding c to the smaller vessel. So, the difference reduces by 2c. You have to find how many operations are required.

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

    Can we say in Problem F , that after eliminating nodes with indegree = 0 (There cost is counted as 2 * C[x] , we are left with only loops (can be different components) , with each node having indegree = 1. Now for each loop , we can just calculate the node that we should remove at the very last so that its cost is counted C[x] while the other ones' cost in the loop is counted 2*C[x] ??

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

      Yes, when there is loop, first you will remove the parent of element with smallest cost first such that element with smallest cost will get removed at last.

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

    In problem G solution is should be a[i] > 1.

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

    In G you brute force if a(i)>1 <=48 , but to be safe I did for <=50

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

    nice solution to G key point was product greater than some max value!!

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

Nice problemset :)

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

Hey cf folks, looking for a coding friend who wants to upsolve with me, would really help if we could discuss answers after a contest gets over.

Also since the editorial is not out yet, can anyone explain me the intuition for problem C ?

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

    If l != r and r is at least 4 then one of the numbers is 2 and the other is floor(r/2)*2-2, this works. If l != r and r is less than 4 there is no answer

    Otherwise we need to find a divisor of l that is not 1 or l, we can bruteforce until sqrt(l) or use the Sieve of Eratosthenes to factorize l. If l is prime then there is no answer

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

      Still not able to understand it >.< I guess I'll leave it at that

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

        Apologies, I realized I didn't explain properly.

        If l = r then the sum of a and b must be equal to l, so if l is prime there is no answer (suppose there was, then there exists c >= 2 that divides a and b and therefore divides l as well which can't happen.) Otherwise we can choose a = min divisor of l that is not 1, and b=l-a.

        Otherwise, notice that a+b >= 4 because a and b are both at least 2. So if r < 4, there is no solution. Otherwise there exists a solution. Consider a = 2. We can choose b such that b is even and a+b is either r or r-1, assuming l != r (we handled the other case above), which is where b = floor(r/2)*2 — 2 comes from.

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

In problem D, I changed n,x, y type from int to long long and it got accepted. How could this be possible? [n maximum is 10^9]

Wrong answer here

Accepted here

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

    ig, it's because in lcm function if u use int values it will gonna return values in int only no matter what data type u r using to store it and lcm of two numbers which is <=10^9 might exceed int limit

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

    You have the line "using namespace std;" so when you call lcm(x,y) with x and y as int it ignores your custom lcm function and uses std::lcm(int,int) as that matches better, but that returns an int so it overflows.

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

      Thanks a lot, that is a lesson learnt, for sure. :(

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

      Hey when I try to use __gcd(a, b) in CF it works. But in my local machine it gives error in sublime text, do you know the reason for it good sir?

      PS: I have a mac, so is it related to clang or something?

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

A: The answer will be cd(abs(a-b), 2*c) because you have to move half the difference from the biggest vessel to the smallest one. and this will take you cd(abs(a-b)/2, c) moves.

B: Each trap forces you to be back past it after s-1 seconds. In that time you can move (s-1)/2 units to the right of that trap and sitll have time to return. Each trap puts on such restriction on your trip, so you just iterate over the traps and do ans = min(ans, d+ (s-1)/2)

C:If l and r are at least 4 apart, there is a multiple of 4 between them, lets call it k, and then k/2 is even, so we can set x= k/2 and y=k/2. If l and r are less than 4 apart, we can brute force all divisors of l, l+1, l+2 .. r. And then if d | l, we can return x = l — d and d. This will always find a solution, because if gcd(a,b) = g, and a+b = k, then g | k. So the answer will always be found among the divisors of the numbers between l and min(r, l+4)

D: You want to put the biggest elements of the permutation of multiples on x, and the smallest on multiples of y. You can ignore the indexes that are multiples of both. However, you can't calculate this naively. because n= 1e9. However, you can use triangle number sum n(n+1)/2. the number of multiples of x that are not multiples of y is n/x — n/lcm(x,y) = k. so do n(n+1)/2 — (n-k)(n-k-1)/2. To get the multiples of x, and do -(y-n/lcm(x,y))((y — n/lcm(x,y))+1)/2 to subtract multiples of y.

E: The array never changes, so we can calculate an XOR prefix array. After this we can calculate the XOR of all the ones-position in the array and all the zero-position in the array.

Then, whenever we are queried, we can just set ones^=prefix[l,r] and zeros^=prefix[l,r]. That is, we set our ones and zeros XOR counters to XOR the XOR of the element in [l,r]. The reason we can do this is because when we invert [l,r], we remove all the ones from 1, and add all the zeros. However, removing the ones is the same as adding the ones because every element is its own inverse under XOR. Same logic applies for zero

F: All the nodes with indegree zero, we can remove with no issues, because no one is afraid of them, so we lose nothing by removing them early. After we've done this, there might be new nodes with indegree zero, so we remove those as well (and add to answer in the order we remove them).

After we've removed all the nodes with indegree zero, there will only be cycles left. This is because every node here has outdegree 1 (they are only scared of one other animal).

So we can go through the cycles and find the animal with the least cost, call it s Then we go through the cycle and remove all elements in order, starting with A[s], and ending with s. That way we get twice cost of all the animals except s (which has least cost, so this is optimal).

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

MathForces

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

Hi

Just checked out the problems and noticed that problem F was 99% same as abc256E

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

    they are not literally same lol, in this problem you have to construct permutation

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

Problem A: does not have to be an integer

Problem B: best illustration in contest

Problem C: even number, not 2, odd number, not prime, not 1

Problem D: sum top for x, sum bottom for y, duplicate LCM

Problem E: Lazy Segment Tree (but not enough time)

Problems are enjoyable! Thank you guys for the contest!

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

I lost D due to a typo long long -> long T_T

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

I solve C like this 222257731.I don’t want to discuss in categories(because I got Time limit exceeded :(

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

One of the best balanced set of question till now every problem was quite awesome !

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

For problem E, I tried to solve it using the segment tree here. I pre-compute the XOR of the entire array a and store the precompute XOR of those values where s[i] = 1 in the tree. So then XOR of those that are zeros in s equals to all ^ one. The time complexity should be $$$O(max(q, n)logn)$$$, but I got TLE. Can anyone tell me what I did wrong?

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

    U don't need segment tree pre calculating XOR of the array just like a prefix_sum is enough. Just think that there's no an actual range update here due to XOR facts..

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

    For range updates you need to use lazy propagation, otherwise if you try to update all values in the range then cost for each update is O(n). If you are given q queries each of size n leading to O(n.q) so the TLE

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

      Ah yes, I forgot the lazy propagation :(. Was spending too much time on thinking about what to store in the segment tree.

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

I made video explaining problems A&B&C&D : https://youtu.be/g7OJ3GVzIhM

I thought it would be useful

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

That's very good contest i liked how does E work i thought that E is segment tree but i did learn a knew thing while thinking that you can make prefix xor , thanks for the contest.

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

In E I did sqrt decomposition lol

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

Does E require square root decomposition ??

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

    it doesn't require but you can overkill with it just like I did

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

      I actually started learning about sqrt decompostion this week, after reading the problem it was the first thing that striked my mind. Even segment trees came as a second thought.

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

Proper Div 3 round after a long time.

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

I didn't expect to learn something new in Div. 3 contests (the lemma about Functional Graphs, I skipped my theory classes :/), so thanks a lot.

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

Video Editorial For problem A to G.

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

Best Contest Ever !

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

That's a very good contest I liked it , thank you codeforces

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

This contest was of great quality. The problems were interesting and challenging and their explanation was clear. Hope this trend will continue in div3 contests.

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

Did somebody notice , that in todays G 1<=a[i]<=1e9 , but in examples they took a[i]=0 in some places .

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

My worst div.3, I solved only A-D(lately, beacuse of C) in contest, upsolved F. For me: C>D, E>F. But I couldn't solve F in contest. Hope better next time.

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

    same :), upsolved F in maximum of 30 minutes, any way good luck to us next time

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

I'm not rly good at maths can someone plz explain how did he solve D by steps

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

I want some hints for problem F. If we make a directed edge graph out of the given things, with

$$$a->b$$$

meaning b is afraid of a, it would mean we actually have to implement toposort when the graph is acyclic. The problem arises when the graph become cyclic.

In that case we observe that for a cycle say,

$$$a->b->c->d->a$$$

, if we start from anywhere, let us say, from d, and go in the reverse direction of the edges, (i.e d->c->b->a), we will get the

$$$profit = 2d+2b+2c+a$$$

. In other words, if we start at node x such that

$$$x->y$$$

is an edge in the cycle, the profit we get is : profit = 2(Sum of profits of all the nodes) - y. This hints that we need to keep track of all the cycles in the graph.

Further we observe that the In Degree of any node will not be greater than 1, It means that two cycles cannot have any node in common, and also any two cycles are disconnected (it can be proved by contradiction). So now the problem reduces to finding the strongly connected components of the graph (as the strongly connected components will only have cycles in them), and then to track the minimum of the nodes present in the cycle.

Is there any efficient way to do this?

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

    Hey you're on the right track. Don't make the question too complicated tho. As you said indegree and cycles are important information for this question. Take some of the given samples, and try to reduce them into solvable graphs.

    Hint :- As each vertex has exactly one outgoing edge, so any cycle if present will be a simple cycle. Also each vertex will always have exactly one outgoing edge, so maybe solving for a cycle isn't that hard.

    You'll get the solution if you try to find a way for the given samples. I solved sample 2 and 6 when I did the question.

  • »
    »
    8 месяцев назад, # ^ |
    Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

    My solution is Change the problem like this: if we sell Animal i there is a cost sum(C[j], for all animal j that afraid of animal i). Using priority_queue you can sell the animal(i) whose cost is minimum currently. And update cost of animal a[i] and push this to priority_queue.

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

    Kahn's toposort algorithm is still useful — it can give you an ordered list of nodes that aren't in cycles (so can be sold for 2*C). You can then just calculate the cycles for any nodes not in that list (using a simple dfs as there is only one option at each node).

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

How to do G? I am totally clueless. Please help.

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

Hey guys I am new to codeforces it was my first contest as rules says it will be rated for all <1600 but in my profile this contest comes under unrated contest ?? Can someone pls explain Also I was able to solve A,B,C in this contest is it decent start ??

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

.

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

    I'm not 100% sure, but I think the real issue is that your n inside function init is greater than the N you used to declare arrays. This can lead to overflow problems and unknown errors, including Wrong Answer. Your submission got AC when your n is smaller than N.

    Actually, your code always gets RE on my computer. It's a little strange why you didn't have this during contest, maybe because you didn't enable O2 optimization when you debugged locally? Specify -O2 can sometimes help expose some issues like overflow :D

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

in contest time to me div2 < div3:)

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

suck the B problem

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

I gave the contest and solve 2 questions but still i am unrated and the this contest is showing unrated for me i don't understand what is this if anyone has idea about this please tell me

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

Hope to become an expert, good luck

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

It is showing rated here but my rating didn't changed and it is showing unrated to me

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

This is my first time to take part in the contest, How long can show my rate ?

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

Cannot understand why people are jumping to segment trees to solve problem e. It's a div3 e, not div2 e!

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

    Maybe coz of it's name !

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

    It's easier for me to think using segment trees.

    Also it's not about solving problems the intended way. It's about being able to apply the tools available to you.

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

    I had like 45 minutes to implement and still didn't manage to do it somehow, I guess I'm not experienced enough with seg trees

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

Happy that I solved first 5 problems in this contest , but could have solve little faster to get good rank. Hope to be Cyan again after rating update.

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

Good contest hope pupils touch cyan their first time after rating

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

I put long long instead of long double when doing G (was working with log10) so got WA when rejudge, weak pretest :v but overall i enjoyed the contest.

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

Hi I want to ask why is this contest unrated for me

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

Can someone please identify the problem with my submission for D? I'm pasting it below for easy reference. Thanks.

222341350

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

It was a very cool round, thanks to the creators!

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

E can be solved without segment tree. It's just xor prefix array.

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

Indians are rocking everywhere.

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

Good Luck Everyone for System Testing.

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

I hope that I became blue. Can I do it ?

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

I have a doubt in question E using segment trees with lazy propogation.

Quoting from editorial: Of course this problem has solutions that use data structures. For example, you can use a segment tree with range updates to solve it in O((n+q)logn).

Should not the time complexity be: O(n + q*log(n))?

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

I got two errors with 222304620 222293819, why did I pass all test cases but still get pending status and these are counted as WA solutions.

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

Why is this round being retested now?

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

I have got a skip on this problem : 222280755 for the problem 1872E

this template of code is shared with me and my friends as we all are in the same training

and the segment tree code is also a template, you can see my previous codes, all of them with the same template, so please give me the points back