sevlll777's blog

By sevlll777, history, 8 months ago, translation, In English

Hello Codeforces! Codeforces Round 895 (Div. 3) will start at Sep/07/2023 17:35 (Moscow time). You will be offered 7 problems with expected difficulties to compose an interesting competition for participants with ratings up to 1600. However, all of you who wish to take part and have a rating of 1600 or higher, can register for the round unofficially.

The round will be hosted by rules of educational rounds (extended ICPC). Thus, solutions will be judged on preliminary tests during the round, and after the round, it will be a 12-hour phase of open hacks.

You will be given 7 problems and 2 hours and 15 minutes to solve them.

Note that the penalty for wrong submission in this round is 10 minutes.

Remember, that only the trusted participants of the third division will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a trusted participant of the third division, you must:

  • take part in at least five rated rounds (and solve at least one problem in each of them)
  • do not have a point of 1900 or higher in the rating.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.

Problems have been created and prepared by: Alexdat2000, FairyWinx, sevlll777, Vladosiya, и MikeMirzayanov.

We would also like to thank:

  1. Vladosiya for the amazing coordination, and help with preparing and balancing a problemset.
  2. MikeMirzayanov for Polygon and Codeforces platforms.
  3. Ormlis for black-red testing.
  4. zwezdinv, BledDest for red testing.
  5. Sokol080808, diskoteka, Sweezy, vladmart, Kniaz, Tima, Riblji_Keksic, 74TrAkToR, pavlekn for yellow testing.
  6. moonpie24, gs20036, Kolychestiy for purple testing.
  7. martin0327, tnaito, no_mind, Pa_sha, SashaT9, ctraxxd, ezdp, BF_OF_Priety for blue testing.
  8. NerfThis, _SADIEM_, YudoTLE, sayed_4 for cyan testing.

Good luck!

UPD: Editorial

  • Vote: I like it
  • +288
  • Vote: I do not like it

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

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

»
8 months ago, # |
  Vote: I like it -12 Vote: I do not like it

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

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

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

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 months ago, # |
  Vote: I like it +11 Vote: I do not like it

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

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

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

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

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

»
8 months ago, # |
  Vote: I like it -11 Vote: I do not like it

Good luck!

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

Big chance to reach green tomorrow

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

    I'll stop saying this... But thank you for the contest, I really enjoyed the problems

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

I hope I don't get hacked again

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

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

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

I will try to solve all :>

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

    you will definitely get expert back :)

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

      This exam is really harder than I thought, I could only solve 5/7 problems: ((

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

        Bro istg i have figured out how E is solved ages ago I just can't implement aparrently

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

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

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

OMG , Janmashtami round

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

Hope to become Cyan in this contest :)

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

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

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

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

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

Good luck!

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

MY first unrated Div 3.

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

Once upon a time when Division3 = Vovuh

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

Hope to reach 1000 in this contest.

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

Hope I can solve 4-5 problems in the round

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

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

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

I'm determined to reach green in this round.

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

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

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

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 months ago, # |
  Vote: I like it 0 Vote: I do not like it

hope to reach at least 1000! :)

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

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

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

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

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

Why My contest habit is bad ?

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

»
8 months ago, # |
  Vote: I like it -12 Vote: I do not like it

mathforces

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

very balanced contest, loved it.

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

$$$t$$$ test cases forces

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

problem C is such a troll problem

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

NumberTheory-Forces

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

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 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Any hint on how to solve problem E?

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

    Segment Tree

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

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

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

        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 months ago, # ^ |
            Vote: I like it +13 Vote: I do not like it

          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 months ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            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 months ago, # ^ |
                Vote: I like it 0 Vote: I do not like it

              how u implemented segment tree, can u explain?

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

                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 months ago, # ^ |
                  Rev. 2   Vote: I like it 0 Vote: I do not like it

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

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

                  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 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          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 months ago, # ^ |
              Vote: I like it +10 Vote: I do not like it
            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 months ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

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

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

      It can be solved with sqrt decomposition too :)222263672

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

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

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

        I'm too lazy to implement lazy segment tree

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

    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 months ago, # |
  Vote: I like it +6 Vote: I do not like it

great contest!

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

How to solve E without using segment tree?

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

    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 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    You can use prefix Xor 222276789

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

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

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

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

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

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 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

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

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

    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 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

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

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

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

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

          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 months ago, # ^ |
            Rev. 2   Vote: I like it +4 Vote: I do not like it

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

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

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

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

    what is wrong with it ?,for me it was clear and helpful.

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

      Ntg's wrong with it except the fact that my brain decided to stop working for few minutes

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

How my brain processed Problem C:

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

Thanks for the contest. It was really amazing.

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

I really liked the problemset

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

it feels so good after solving E.

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

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

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

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

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

.

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

    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 months ago, # |
  Vote: I like it +1 Vote: I do not like it

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

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

    How did you solve G?

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

      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 months ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        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 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

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

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

          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 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

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

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

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

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

Amazing set of problems & a great contest!

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

Have someone did F with path compression ?

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

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

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

      Yup

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

        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 months ago, # |
Rev. 9   Vote: I like it +9 Vote: I do not like it

Quick Editorial:


Problem A

Problem B

Problem C

Problem D

Problem E

Problem F

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

    How to come up with the formula for problem A?

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

      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 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

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

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

          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 months ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Thanks mate! Finally understood the thought process behind the formula :)

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

    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 months ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      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 months ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

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

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

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

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

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

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

Nice problemset :)

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

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 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

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

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

        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 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Thanks brother! Finally after spending an hour again I was able to fully solve it :)

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

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 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

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

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

      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 months ago, # |
  Vote: I like it +2 Vote: I do not like it

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 months ago, # |
  Vote: I like it -15 Vote: I do not like it

MathForces

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

Hi

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

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

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

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

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 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

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

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

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

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 months ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    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 months ago, # ^ |
        Vote: I like it +1 Vote: I do not like it

      Oh thanks! I re-implemented and it got accepted!

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

    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 months ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

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

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

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

I thought it would be useful

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

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 months ago, # |
  Vote: I like it 0 Vote: I do not like it

In E I did sqrt decomposition lol

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

Does E require square root decomposition ??

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

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

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

      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 months ago, # |
  Vote: I like it +1 Vote: I do not like it

Proper Div 3 round after a long time.

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

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 months ago, # |
  Vote: I like it +3 Vote: I do not like it

Video Editorial For problem A to G.

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

Best Contest Ever !

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

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 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

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

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 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

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

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

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

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

    Learn inclusion exclusion and you should be able to get it.

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

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 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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 months ago, # ^ |
    Rev. 2   Vote: I like it +1 Vote: I do not like it

    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 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    well yes , it is a decent start and the contest will change to rated after 1 day ig.

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

.

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

    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 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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 months ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    Don't worry it will take some time to update the ratings

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

    There was a hacking phase...now system testing will take place , after that they will update ratings. Probably wait for 3-4 hours

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

Hope to become an expert, good luck

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

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

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

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

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

    Maybe coz of it's name !

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

    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 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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 months ago, # |
  Vote: I like it +4 Vote: I do not like it

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 months ago, # |
  Vote: I like it +1 Vote: I do not like it

Good contest hope pupils touch cyan their first time after rating

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

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 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

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

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

222341350

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

    I think there is something wrong with this line

    score=n*num_x-int((num_x)*(num_x-1)/2)

    why are you multiplying n*num_x?

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

    maybe overflow like issue? logic wise it seems correct

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

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

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

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

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

Indians are rocking everywhere.

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

Good Luck Everyone for System Testing.

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

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 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Why is this round being retested now?

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

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