_istil's blog

By _istil, 6 weeks ago, In English

Thank you for participating in this round! Problems A and G are authored by Cocoly1990 and the rest by me.

Currently, I'm not sure if the editorials are fine enough. Please feel free to tell me where I can improve.

Rating Predictions

2053A - Tender Carpenter

Hint 1
Hint 2
Hint 3
Solution
Code (C++)
Rate the Problem

2053B - Outstanding Impressionist

Hint 1
Hint 2
Solution
Code (C++)
Rate the Problem

2053C - Bewitching Stargazer

Hint 1
Hint 2
Solution
Code (C++)
Rate the Problem

2053D - Refined Product Optimality

Hint 1
Hint 2
Solution
Code (C++)
Rate the Problem

2053E - Resourceful Caterpillar Sequence

Hint 1
Hint 2
Hint 3
Solution
Code (C++)
Rate the Problem

2053F - Earnest Matrix Complement

Special thanks to LMydd0225 for implementing a correct MCS ahead of me, and Error_Yuan for generating the test data for this problem.

Hint 1
Hint 2
Hint 3
Hint 4
Solution
Code (C++)
Rate the Problem

2053G - Naive String Splits

Special thanks to LMydd0225 for generating the test data for this problem, and TheScrasse for providing an alternative solution.

Hint 1
Hint 2
Hint 3
Solution
Optimization to Linear
...wtf?
Code (log, C++)
Code (linear, C++)
Rate the Problem

2053H - Delicate Anti-monotonous Operations

Special thanks to LMydd0225 and N_z__ for developing this problem.

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Solution
Code (C++)
Rate the Problem

2053I1 - Affectionate Arrays (Easy Version)

Hint 1
Hint 2
Hint 3
Solution
Code (C++)
Rate the Problem

2053I2 - Affectionate Arrays (Hard Version)

Hint 1
Solution
Code (C++)
Bonus
Rate the Problem
  • Vote: I like it
  • +131
  • Vote: I do not like it

»
3 days ago, # |
Rev. 2   Vote: I like it +122 Vote: I do not like it

Fun fact:

PS: It's three minutes before the contest starts.

  • »
    »
    38 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Hi, is this a public discord channel that we can join? Would love to know more ppl.

»
3 days ago, # |
  Vote: I like it -18 Vote: I do not like it

D was a cool one imo

»
3 days ago, # |
  Vote: I like it -15 Vote: I do not like it

C and D was difficult or I fckd up

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

    D was easy, C was tough i guess. I still can't figure out how to do it.

    • »
      »
      »
      3 days ago, # ^ |
      Rev. 2   Vote: I like it +13 Vote: I do not like it
      hint 1
      hint 2
      hint 3
      hint 4
      hint 5
      hint 6
»
3 days ago, # |
  Vote: I like it +9 Vote: I do not like it

Sucks could've solved E if I had known how to do tabulation DP. My memoization with unordered_map didn't pass even though O(n) complexity.

  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Are you sure your code is O(n)?

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

    Consider a tree with 1 internal node and n leaves.

    • »
      »
      »
      3 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Yeah I guess that would iterate O(n^2) so I would need some other method.

»
3 days ago, # |
  Vote: I like it +9 Vote: I do not like it

Fast editorial forces

»
3 days ago, # |
  Vote: I like it +80 Vote: I do not like it

predicting [800, 3000] for I is diabolical

»
3 days ago, # |
  Vote: I like it +1 Vote: I do not like it

I really enjoyed in solving B!!(although am a noob:( )

»
3 days ago, # |
  Vote: I like it +11 Vote: I do not like it

I liked I1 very much, it was very fun

»
3 days ago, # |
Rev. 3   Vote: I like it +508 Vote: I do not like it

wyrqwq I believe the model solution for I2 (as well as the solution I was trying to write, and all the ones that have AC) are wrong — they might overcount arrays $$$b$$$ with consecutive equal elements.

For example, on

1
4
3 -4 4 3

the solution outputs 6 but I could only find the following 5 solutions with exhaustive search:

1 3 -4 4 -1 3
2 3 -4 4 -2 3
3 1 -4 4 -1 3
3 2 -4 4 -2 3
3 3 -4 4 -3 3

(I believe the last solution is being double counted.) Can this be addressed?

  • »
    »
    3 days ago, # ^ |
    Rev. 2   Vote: I like it +93 Vote: I do not like it

    This is very disappointing: I believe the same, and currently, we are discussing the issue.

    The most boring solution is to change the statement so that it fits the code, but that's too stupid.

    • »
      »
      »
      3 days ago, # ^ |
      Rev. 4   Vote: I like it +128 Vote: I do not like it

      As someone who did not solve either version of I2 during the contest, I would prefer that I2 just be removed from the contest. :)

      (After all, none of the solutions that currently have AC are actually correct ...)

      • »
        »
        »
        »
        3 days ago, # ^ |
        Rev. 2   Vote: I like it +18 Vote: I do not like it

        I think in this case (expected extremely hard problem turns out to be almost unsolved + wrong), this would be best:

        • Since standings will be hardly affected (almost nobody even reads the last problem), keep standings as is and offer to remove people who can demonstrate they were negatively affected.
        • For upsolving/practice, change the statement to match the official (wrong) solution, with a big red note how it was different in contest.

        As I understand it, accepted solutions are counting pairs (B, mask) where B[mask] = A instead of just counting sequences B? That should be easily editable and as long as there's no other mistake, it's kind of a waste to remove a prepared and published problem.

        Also when prizes are involved, give out prizes based on the corrected standings after item 1. While trying to solve I2 could've given someone a worse spot than if the problem was correct, unfortunately it's impossible to prove so anyone who got a prize but lost rating can only choose between accepting both or rejecting both, and it has to be a choice by contestant.

        • »
          »
          »
          »
          »
          3 days ago, # ^ |
          Rev. 4   Vote: I like it +77 Vote: I do not like it

          I agree with most of your points (people who were adversely affected can petition to have the contest unrated, statement can be changed to reflect the official solution, fine to keep this problem for practice purposes).

          But I don't think it makes sense to have this problem count towards the contest standings given that the ACs do not correctly solve the problem statement that was given in-contest.

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

            Yeah, that's a valid point.

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

          Since standings will be hardly affected (almost nobody even reads the last problem), keep standings as is and offer to remove people who can demonstrate they were negatively affected.

          I doubt this point. This time >=150 people solved I1, so I suppose most of those people got non-trivial information about what I2 is, and I wouldn't say the number of people who put some effort on I2 is "almost nobody" — well this is a subjective word, but I would say more than half of people in the battle in rating >=3000 got unfair effect changing their ranks.

          (Not an opinion from my personal point of view; I read I2 but spent only a few minutes, so my rating drop was just about right or should have even been larger.)

          For being unrated or not, it's up to how Codeforces values on the rating. Perhaps rating is just a number.

          • »
            »
            »
            »
            »
            »
            3 days ago, # ^ |
              Vote: I like it -28 Vote: I do not like it

            The information "go for I1, it's pretty easy!" is in the standings — I definitely took advantage of it, even though I often check first subtask of hard problems, I otherwise avoid spending significant time on it or keep it for last. If you've used that information, you've most likely looked at the standings after and saw that the number of solutions for I2 is vastly lower, so it should be treated as a super hard final problem and not as something with similar difficulty.

            Either way, anyone who hasn't submitted for I2 won't be directly affected by official solution being wrong; those who submitted and didn't fail sample are like 10 people, and they can request getting contest skipped.

            The decision making process regarding how much time to spend before submitting isn't affected either since it's a hard subtask that mimics a hard subtask.

            This is ultimately about choosing the least bad option (unrated is Exterminatus, when any attempts to salvage the situation are worse than making it all gone — admittedly a very common situation), about how to deal with effects of the wrong solution+tests. There's a ripple effect on those who don't submit, but compared to a general mistake to spend a lot of time on [hardest problem hardest subtask almost no solutions], it should be very small, so this is a salvageable situation.

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

              For me, the solution of I1 gives (or hints) you a direct way to solve the wrong version of I2. I would expect at least half of the people who solved I1 were affected.

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

                What does that have to do with the official solution being wrong? I don't understand. It's your choice to solve the wrong version.

                In other words, if there was a correct official solution for I2, what would've changed for everyone who got "hinted" at wrong solution by I1? Note the actual number of people who submitted anything and passed pretest 1 is visible.

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

                  Unfortunately, pretest 1 was wrong.

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  3 days ago, # ^ |
                    Vote: I like it 0 Vote: I do not like it

                  Oh. That's a much bigger problem. I was working on the assumption of "as long as there's no other mistake". That's certainly pushing it into unrated territory, especially combined with O(N^2) passing on E.

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

                  I don't understand your point. People stop writing when they realize it is wrong.

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  3 days ago, # ^ |
                    Vote: I like it -36 Vote: I do not like it

                  Did you read this and this? Under that assumption (applies to everything that I wrote above), people would only realise it's wrong once they submit and pass pretest 1, and we know that number to be very small. None of what you wrote matters, they're complete non-sequiturs, what matters is that the assumption I made was wrong.

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  3 days ago, # ^ |
                  Rev. 2   Vote: I like it +24 Vote: I do not like it

                  Well, for E, inefficient time complexity passing a problem is something that happens all the time, and it's not a real issue (problemsetters can't predict every wrong approach of the problem). The pattern needed to hack your solution was not one of the typical tree shapes, so probably they missed it. I didn't find too many other solutions that can be hacked with the same test either.

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  3 days ago, # ^ |
                    Vote: I like it -7 Vote: I do not like it

                  Why would people only realize it's wrong once they submit and pass pretest 1 even given your assumption? (What even is your assumption though?)

                  No matter what was happening in the pretest 1, why can't you like this comment, notice it is wrong during coding or before coding? This has nothing to do with any of your assumption about pretest 1.

                  My point is, the wrong version of I2 is not that hard given that you have solved I1. After solving I1, people spent time noticing the wrong version of I2 is not the correct problem statement, and concluded that I2 is nontrivial. They(We) are definitely affected by the wrong I2.

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

                  After solving I1, people spent time noticing the wrong version of I2 is not the correct problem statement, and concluded that I2 is nontrivial.

                  and what changes for they(you) from the scenario where I2 was solvable but hard?

                  there is no difference from your perspective....

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  39 hours ago, # ^ |
                    Vote: I like it -18 Vote: I do not like it

                  You're asking me about things in the linked comments. Read. That's literally all you need to answer your own questions: reading&comprehension.

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  39 hours ago, # ^ |
                    Vote: I like it -10 Vote: I do not like it

                  That's quite surprising considering it's a simple dumb code that I quickly put together because end of the contest was close. It's not even something I fully thought up by myself, just inspired by some stuff I've seen, though badly applied.

                  Oh well, unlucky some times, lucky other times.

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

      Is there any precedent to this? The closest I can think of is this problem and the entire div.1 was unrated.

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

    Last year at GoodBye2023 there were also some mistakes by the authors, which seemed to me to be much larger. So I hope that this next year will be better than the previous one)

    I also wonder if anyone was able to come up with the right solution for I2 or is it impossible?

    P.S. Also here is my experience of solving this problem: looked closely at the code for I1 -> hmm this should be improved to I2 by simply adding a few structures -> started writing the code -> after 5 minutes realized that some arrays are taken into account several times -> stop writing -> think -> go to problem H.

»
3 days ago, # |
  Vote: I like it +7 Vote: I do not like it

Overall a tough contest

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

Why did my code for E get TLE even though I think my code is O(nlogn)?

298891273

I also had O(n) code that got TLE. Can someone please explain why? Thanks!

  • »
    »
    3 days ago, # ^ |
    Rev. 2   Vote: I like it +19 Vote: I do not like it

    Consider a tree with 1 internal node and n leaves.

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

      Do you know where it specifically is getting TLE?

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

        Consider a tree with 1 internal node and n leaves.

        while (s.size()) {
            pii p=*s.begin();
            dfs(p.first,p.second);
            if (s.find(p)!=s.end()) s.erase(p);
          }
        

        Then,

        for (int j=0; j<adj[cur].size(); j++) {
            if (p!=adj[cur][j]) {
              if (sec[cur][j]==-1) dfs(cur,j);
              totx+=sec[cur][j];
            }
          }
        

        For p.first=1.Since you have n edges in the node,and for all edges you will visit all edges again,which leads to $$$O(n^2)$$$

»
3 days ago, # |
  Vote: I like it -11 Vote: I do not like it

Great round! Love it

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

Centroid decomposition for E 298885664 Can this be hacked?

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

In A what if the test case array is 115,9,110. Should it be yes because in question it said partition can range from 1 to n.

  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    The answer is NO in this case as there's only ONE way for partitioning: [115], [9], [110]

    • »
      »
      »
      3 days ago, # ^ |
        Vote: I like it -13 Vote: I do not like it

      The partitioning size in question was written. 1 to n so can't it be the complete array of all elements ie [115,9,110]

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

        if you choose the complete array, the triplet $$$(9, 9, 110)$$$ can't form a triangle. Note how the elements of the triplets do not need to be distinct.

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

what was the intuition behind c today, can anybody help? i spent almost 2 hours thinking of how to approach it

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

    Well if you plot the answers for some smaller value , you can see that it follows a set pattern . So for every subtree for which you know the answer you can find the value for its adjacent tree.
    I used a bottom up approach and started from the smallest valid group up to the actual value of n and handled the odd and even cases differently.
    My submission : 298887432

  • »
    »
    3 days ago, # ^ |
    Rev. 3   Vote: I like it +5 Vote: I do not like it

    Let's think about maintaining the following variables at each level:

    • The number of segments $$$c$$$,
    • The number of elements in each segment $$$w$$$, and
    • The sum of the first elements of all segments $$$s$$$.

    Then it's possible to calculate the sum of lucky values for the current level (if $$$w$$$ is odd).

    Detailed solution
    More explanation on calculation of s
    • »
      »
      »
      3 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thanks! After 30 minutes of thinking I figured out why your fomulas actually work. Nice and neat solution.

      Nevertheless, don't know how to come up with this during round. It's more of intuition, I know, and should be trained by constant practicing, but anyway a bit sad that constructive problems cannot be trained constructively :(

      • »
        »
        »
        »
        3 days ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        It was not easy for me, either. I was stuck in this problem for a long time (I actually solved D much faster). After many failed attempts, I suddenly realized $$$s$$$ is a good summary of the current split of segments.

        Maybe the key insight here is that the shape of all segments is similar. Let's say we have segments $$$[1, 2, 3, 4, 5]$$$ and $$$[6, 7, 8, 9, 10]$$$. In the next level we'll have four segments split like $$$[[1, 2], *, [4, 5]]$$$, $$$[[6, 7], *, [9, 10]]$$$ (where $$$ * $$$ denotes the removed elements). We can generalize each segment as $$$[[a, a+1], *, [a+3, a+4]]$$$ -- that is, relative offsets within each segment are the same among all segments. Then you might be able to derive that $$$s$$$ can be used to represent the current segment split.

    • »
      »
      »
      3 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      thank you very much!

    • »
      »
      »
      3 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Wow, this is a very neat explanation, and appropriate for lower rateds like me who are having problems solving C. Thank you! I couldn't make progress at all with the official editorial but with this explanation, I could derive the same formulas and implement a correct solution in less than 20 minutes. Wish I thought of this during the contest :) Thank you very much!

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

@_TernaryTree_

Could you help me review my code which is very much similar to yours? I did somewhat like this,

for reference , my sub: 298897695

//maintain three variables 
//let c be the first value to be added in a round ,then 

a=0,b=0,c=-1;
while(n>=k){
if(n&1)
{
 a += (1LL<<b);
 if(c==-1) c = (n+1)/2;
}
b++;
n/=2;
}

//then
ans = c*a;

while this worked for first 5 pretest cases , it failed on 6th one but i find it interesting how this pattern works. now,

  1. why does your approach works but mine fails? why did you initialise mul as (n+1) and not the first value which we get if the segment length is odd? i mean how did this idea hit? except for the last case which i could not simulate , my idea for mul(==c) works good till pretc 5.

  2. why do you apply /2 after multiplying sum and mul? why not do mul / 2 before ?

nevertheless, Appreciated the round. Thank you.

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

    Can it be tried using the recursion? If we can reduce the TC somehow?

  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    check my submission, i think the problem is how you calculate c

    • »
      »
      »
      3 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Yes. It is how i calculate c which is the issue here.

      Also. I figured out why this solution works. Great question. Great solution.

      • »
        »
        »
        »
        3 days ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        can you post your updated code and explain line by line why it works i just kinda coded until it passed, idk

»
3 days ago, # |
  Vote: I like it +1 Vote: I do not like it

What are x and y in C? Could somebody please explain?

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

    The parent segment gets divided in 2 subsegments, x and y are middle index of that subsegment. And x + y = n + 1.

    Ex: n = 22 , k = 4 First Segment : [1 , 2 .. . . 22] as Even length so subsegment [l , m] & [m+1 , r].

    Second Segment : [1 , 2 , ..... 11] & [12 , 13 , .... 22]

    Here x = 6 , y = 17 and x + y = 23 which is 22 + 1.

    I have not discussed about [12 , 13 ... 22] you can analyse it.

    Third Segment : [1 , 2 .. 5] & [6] & [7 , 8 , ,... 11] as Odd length so subsegment [l , m-1] & [m] & [m+1 , r].

    Here x = 3 , y = 9 and x + y = 12 which 11 + 1.

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

For A, why 10, 2, 10 is not a valid answer? 10 + 2 > 10 10 + 10 > 2 2 + 10 > 10

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

    the set{10,2} has 2 possible triplets

    10 10 2

    and

    2 2 10

    only one of these is valid

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

    its a valid answer , but the question says for all possible combinations.

    i.e , if you are choosing a segment [2,10] then all the combinatoins 2,2,10 and 10,10,2 must satisfy this condition , but 2 + 2 is not greater than 10 that's why it will not be the case.

    • »
      »
      »
      3 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Didn't notice "for all possible combinations" part :'[ Tnx

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

i don't understand editorial for C, who can help me?

  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    check my solution, I produced it after slogging 3 hours on it.

    such a brick problem

    • »
      »
      »
      3 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I check your solution later , I am so tired , but thank you for reply

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

getting TLE on B, seems like approach is fine , but I am missing some basic stuff.

Can anyone check my solution? https://codeforces.net/contest/2053/submission/298900263

P.S. got the issue, it was related to size of vector.

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

    In your code,

    int sz = 4 * (1e5) + 2;
    vector<int> ump(sz);
    vector<int> run(sz);
    

    Each testcase independently allocates 8e5 ints. However if you have t=10000 testcases, your program will end up allocates roughly 8e9 ints, which causes a TLE.

    simply changing your sz to 2*n+1 will get an AC

»
3 days ago, # |
Rev. 2   Vote: I like it +40 Vote: I do not like it

wyrqwq I believe there is a typo in the DP transition for problem F, the correct transition should be

$$$ f_{i, j} = \max(\max\limits_{1 \leq w \leq k}(f_{i-1, w} + c_i \cdot d_{i-1, w} + c_{i - 1} \cdot d_{i, j}), f_{i-1, j} + (d_{i, j} + c_i) \cdot (d_{i-1, j} + c_{i-1}) - d_{i, j}d_{i-1, j}). $$$
»
3 days ago, # |
Rev. 2   Vote: I like it -8 Vote: I do not like it

For H, I'm not seeing how the answer is n*(w-1) for w>=3.

If n=3,w=5,a=[3,3,3]

Shouldn't answer be sum([3,4,5])=12 and not 14??

Am I missing something??

  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    you can first make the array equal to [3,3,5] in one move and then make it equal to [4,5,5] in the next, making the sum equal to 14. Notice that the condition is that a_i is different only to a_(i+1) and it doesn't specify that for example it has to be different from a_(i-1).

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

Question D:

what's the logic behind qpow in code present in tutorial? I know that we have to remove the previous xth value and then update with new xth value if needed

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

    I didn't understand this at first either, but it's a consequence of Fermat's little theorem. If X is prime, then for any integer A:

    A ^ (X - 1) = 1 mod X

    Then we can multiply both parts by our previous answer Y:

    Y * A ^ (X - 1) = Y mod X (if Y < X, which is true, because we took modulo of Y earlier)

    So if Y is our previous answer, and we need to divide it by A modulo X, we get:

    (Y * A ^ (X - 1)) / A = Y * A ^ (X - 2)

    qpow itself is a function, which calculates mod - 2 power of number modulo mod.

  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    When you are dividing A by B and taking mod with m, you need to instead multiply A by modular multiplicative inverse (modinverse) of B with respect to m.

    If m is prime, modinverse is calculated as pow(B, m-2)

    Hence, in this case, (A/B)%m == (A * pow(B, m-2))

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

great round! better than goodbye 2023 :) ehehe

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

can anyone please explain the last test case for problem C? 8765432 is apperantly a randomly choiced even number no where close to power of 2 and yet it get all the score from 1 to itself.

however that's not true for input like 6 1 which has only score of 3

  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    When $$$k=1$$$, Iris observes all of the stars for any $$$n$$$.

    • »
      »
      »
      3 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      oh, that makes sense. thank you for the explaination

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

//

»
3 days ago, # |
  Vote: I like it -76 Vote: I do not like it

I love the coordinator's (or anybody else who answers the questions) work for the problem E. Nothing in the statement says that we will change $$$p$$$ or $$$q$$$, only some sequence of vertices. So I asked the question about it, and their answer was brilliant...

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

    It's written "whenever p is a leaf, Nora wins, whenever q is a leaf, Aron wins. If INITIALLY p and q are both leaves, it's a tie". If p and q weren't changing then this statement wouldn't make sense.

    • »
      »
      »
      3 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      But there is no word in the statement that says that $$$p, q$$$ are changing, so I asked to confirm my guess. Why didn't they answer with a word "yes", instead they referred to the statement ?

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

        Maybe they just misunderstood your question. For example, I read it as "can the first player only move the head and the second — only the tail?" at first

    • »
      »
      »
      3 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      While I agree that the fact that $$$p$$$ and $$$q$$$ are moving is rather obvious, it isn't explicitly written anywhere, so the answer to the question should contain that information.

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

Can D be solved Without Using the Binary_search in between the implementation We can store the {l,r} for each and every unique element as the starting and the ending index and whenever we want to change particular index we take the value of that and take the first element of it from the range {elel,eler} where elel=left indx of element and eler=right index(starting or ending index in the sorted array) and give the element rth(right) index to the element+1, and the lth(left) index and rest from (l-1,l,l+1,...,r-1) all are ele so there would be no change and perform the operations accordingly.

Sorry for bad English.

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

Sorry, I don't understand the editorial for C. Since higher rated people likely don't need tutorial to solve C, can you explain it in a way that is understandable to us lower rated folks?

  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    The solution comes down to a single observation that if [l,m1] and [m2,r] are two halves of the segment [l,r], then the values we add to the answer while processing [m2,r] are the same as the values we add while processing [l,m1] just shifted by (l+r)/2.

    • »
      »
      »
      3 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thank you but how does that help us when there are 4 segments, 8 segments, etc?

      • »
        »
        »
        »
        3 days ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        You never have to consider these cases explicitly. The point is that we don't need to process [m2,r], so we split only [l,m1] and apply our observation recursively.

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

Can anyone help me with understanding the solution to the problem C? The editorial is not quite helpful to me, not sure what x & y they have assumed.

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

    so imagine n=22, k=4

    since we have an even length, we need to split the array into [1,11] and [12,22]. now both subarrays are odd length, so we need to add their middle index, which is 6 and 17. in this case, x=6 and y=17, where x+y = 6+17 = 23 (notice how it's n+1)

    moving on to the next split, we have 3+9+14+20 = 46 (notice how it's 2*(n+1)). so we can generalize that each split downwards multiplies (n+1) by 2, and we should add this value if the current subarray length is odd.

    if n is odd, we can add ceil((n+1)/2) to the answer

    • »
      »
      »
      3 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thanks so much for explanation!

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

      Wowwww!! This is super explanation!! Really Helpful. Thank you and keep it up!

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

Can anyone please explain this testcase in problem B:

5

1 1

3 3

4 4

2 3

1 2

I think we cannot have a unique impression simultaneously for i = 4 and i = 5, please help with this.

  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    independently for each $$$i$$$

    It means when you consider for $$$i=4$$$,you don't need to consider $$$i=5$$$,and so on.

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

somehow the approach for B was not as intuitive to me during practice, I ended up implementing a solution on the same lines as that of prefix sum but in a different way, could someone help me by looking at the submission to let me know if I complicated it a bit and there does exist an easier workaround at some point . Submission

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

in the editorial solution of C ,in the line at the end: cout << mul * sum / 2 << endl; why it has been multiplied by mul?can anyone explain..

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

Can we please normalise mentioning what [.] operation stands for (whether it is ceil or floor)? (C did not specify what it exactly was)

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

Can somebody help me with my code for problem B. 298926051 298926337

The only difference between the two codes is a commented code at the end of second submission. But the outputs for the first test case are different. How is that possible?

  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    // int n; // cin >> n;

    Even if you simply put this at the end of the code it says segmentation fault. It's because you are using n in your code and then kind of redeclaring it even though its commented out. To check this simple change the variable n in the above commented code to some other variable which you did not use in the code (some thing like "var") then it works.

    TLDR : using the variable name again (even though commented out)

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

Could someone help me understand why my code for E 298930084 is giving TLE? I am probably doing something stupid somewhere but can't spot it.

Edit: Never mind, I found the mistake.

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

Can somebody tell me, why this code produces wrong answer on the last case of sample.

I am only calculating left segment answer, and the answer right segment is calculated by adding how many nodes contributed in left segment * m , the i add both of them.

int n,k;
cin>>n>>k;


        int c = 0;
        auto rec = [&](auto&&self, int l, int r)-> long long{
            if(r-l+1<k){
                return 0;
            }
            if(l==r){
                c = 1;
                return l;
            }

            int m = (l+r)/2;
            int d = r - l;
            int ans = 0;
            if(d&1){
                int a = self(self,l,m);
                int b = c * m + a;
                c*=2ll;
                ans = a + b;
            }
            else{
                int a = self(self,l,m-1);
                int b = c * m + a;
                c=2*c+1ll;
                ans = m + a + b;
            }
            return ans;
        };
        int res = rec(rec,1,n);
        cout << res << "\n";
»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Can D be solved Without Using the Binary_search in between the implementation We can store the {l,r} for each and every unique element as the starting and the ending index and whenever we want to change particular index we take the value of that and take the first element of it from the range {elel,eler} where elel=left indx of element and eler=right index(starting or ending index in the sorted array) and give the element rth(right) index to the element+1, and the lth(left) index and rest from (l-1,l,l+1,...,r-1) all are ele so there would be no change and perform the operations accordingly.

Sorry for bad English. Please can someone tell.

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

Can anyone explain the solution for C which is given in the editorial.

»
3 days ago, # |
  Vote: I like it +7 Vote: I do not like it

BTW the quality of the editorial can be improved a lot!!!

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

Can anyone explain question C (what's going on)

»
3 days ago, # |
  Vote: I like it +5 Vote: I do not like it

Thanks for the Editorial!

For problem F, I think there is a missing term, namely: c[i-1]*d[i][w], on the left side of fij relation. Is this true or I'm missing something?

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

for problem C, I had the following code. ~~~~~ This is my code. t = int(input()) for i in range(t): n, k = map(int, input().split()) binary_n = bin(n)[2:] binary_k = bin(k)[2:] digit_count_n = len(binary_n) digit_count_k = len(binary_k) diff = digit_count_n — digit_count_k #this is non negative considerate_n = int(binary_n[:digit_count_k]) if considerate_n >= int(binary_k): iterations = diff + 1 else: iterations = diff new_diff = digit_count_n — iterations multiplier = int(binary_n[new_diff:], 2) increaser = (n + 1) / 2 print(int(multiplier * increaser)) ~~~~~

I checked using python's hypothesis library, if the code given in the solution, and my code return different answer in any case, it couldn't find any example. I am now very very sure my solution is correct, though I may be wrong. But it says failed on pretest 6. Can anyone please help, what should i do?

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

for Problem C can anyone help me out in this submission 298817735 how he come up with the calculation for top_left? its(ecnerwala's soln btw)

  • »
    »
    37 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    The code does pretty much the same thing as explained in my comment. Take a look at it.

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

Can someone explain the solution of Problem B?

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

    If we want to find the answer for some interval i, we need to try every value v between li and ri and check whether we can choose a value that is different form v for every other interval. Well, for every interval with length at least 2, we can always choose a value form this interval that is not equal to v. So our problem is only in intervals i such that li equals ri, because for those we must choose li as their values. So the problem is going to be like this: For each interval i with length at least 2, find out whether there is a value li <= v <= ri such that there is no other interval j: lj = rj = v. To do this, we can build an array f that is initially filled with zeros, and for every 1-lengthed interval i we assign f[li] = 1. Now to find the answer for interval i, we just need to check if there is some value li <= v <= ri such that f[v] = 0 i.e. the values from f[li..ri] are not all ones. Here, it's enough to calculate the sum of values f[li..ri] and compare it with the length of the interval ri-li+1. To calculate the sums efficiently you can use prefix sum. Note that intervals with length 1 need to be handled separately, just check if the interval [li, ri] occurs no more than once.

    Here is my implementation: 298817661

»
43 hours ago, # |
  Vote: I like it -10 Vote: I do not like it
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;// find_by_order -> iterator of kth value, order_of_key -> number of elements less than k

template <typename T>
struct OrderedMultiset
{
    ordered_set<pair<T, int>> s;
    map<T, int> m;
    void insert(long long element)
    {
        int count = m[element];
        pair<long long, int> p = {element, count};
        m[element]++;
        s.insert(p);
    }

    void erase(long long element)
    {
        if (m.find(element) == m.end())
            return;
        int count = m[element];
        if (count == 1)
            m.erase(element);
        else
            m[element] = count - 1;
        pair<long long, int> eraseP = {element, count - 1};
        s.erase(eraseP);
    }

    int upper_bound(long long element) { return s.order_of_key({element, INT_MAX}); }
    int lower_bound(long long element) { return s.order_of_key({element, -1}); }
    
    long long atIndex(int index) { return (*s.find_by_order(index)).first; }
    bool exists(long long element) { return m.find(element) != m.end(); }
    int occurences(long long element)
    {
        if (m.find(element) == m.end())
        {
            return 0;
        }
        return m[element];
    }
};

void solve()
{
    ll n, q;
    cin >> n >> q;

    vector<ll> arr(n), brr(n);
    for (auto &val : arr)
        cin >> val;
    for (auto &val : brr)
        cin >> val;

    OrderedMultiset<ll> crr, drr;
    for (auto val : arr)
        crr.insert(val);

    for (auto val : brr)
        drr.insert(val);

    ll ans = 1LL;
    for (ll i = 0; i < n; i++) {
        ans = mod_mul(ans, min(crr.atIndex(i), drr.atIndex(i)), MOD);
    }

    cout << ans << " ";

    while (q--)
    {
        ll o, x;
        cin >> o >> x;
        x--;

        if (o == 1)
        {
            ll prev_value = arr[x];
            crr.erase(prev_value);

            arr[x] = (arr[x] + 1) % MOD;
            crr.insert(arr[x]);

            ll idx = crr.lower_bound(arr[x]);

            ll cvalue = crr.atIndex(idx);
            ll dvalue = drr.atIndex(idx);
            ans = mod_div(ans, min(prev_value, dvalue), MOD);
            ans = mod_mul(ans, min(cvalue, dvalue), MOD);
            
        }
        else
        {
            ll prev_value = brr[x];
            drr.erase(prev_value);

            brr[x] = (brr[x] + 1) % MOD;
            drr.insert(brr[x]);

            ll idx = drr.lower_bound(brr[x]);

            ll cvalue = crr.atIndex(idx);
            ll dvalue = drr.atIndex(idx);
            ans = mod_div(ans, min(cvalue, prev_value), MOD);
            ans = mod_mul(ans, min(cvalue, dvalue), MOD);
        }

        cout << ans << " ";
    }
    cout << "\n";
}

why This code giving me TLE for Problem D, am I missing Out something?, I think time complexity for the code will be O(qlogn + nlogn).

  • »
    »
    42 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    OrderedMultiset is way too slow. I also struggle with using it in contest, but after I realized that I can use just vector.

»
39 hours ago, # |
  Vote: I like it -16 Vote: I do not like it

Problem B is not a good problem from anypoint , it is done only by observing of given testcases not by any good logic.

  • »
    »
    39 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    It is a good problem, all you had to is fundamentally think if you have to somehow make i unique, what all thingies can trouble you. At the end you'll realize that any number that has atleast 2 values can never cause i to lose uniqueness, only the ones with l==r can,from then on its on your implementation skills how you will efficiently handle this.

»
39 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Overall a hard contest. Couldn't solve C. B and D are good but very doable questions. I did a bad lengthy imple for D but otherwise it's fine.

»
37 hours ago, # |
Rev. 2   Vote: I like it +3 Vote: I do not like it

Will try to explain Part 4. of $$$E$$$.

For Aron to win on $$$k = 2$$$, he must
$$$-$$$ reach a node $$$q$$$ that is adjacent to at-least 1 leaf.
$$$-$$$ from a node $$$q'$$$ which is not a leaf.

For a node $$$q$$$ to be adjacent to at-least $$$1$$$ leaf-
$$$1.$$$ $$$degree[q] > 1$$$
$$$2.$$$ $$$d[q] ≠ degree[q]$$$ where $$$d[q] =$$$ number of adjacent nodes to q that are not leaves.

Number of potential $$$q'$$$ for $$$q$$$ is equal to $$$d[q]$$$. One of them will be on the simple path $$$(p, q)$$$. So we do $$$d[q] - 1$$$ as explained in the editorial.

»
27 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Is there a way to check my submission to I2 on the contest day? I don’t mind if it’s removed from the contest results, but I would like to confirm the submission itself.

»
27 hours ago, # |
Rev. 8   Vote: I like it +8 Vote: I do not like it

In problem F, "The transfer should be as follows:

fi,j=max(max1≤w≤k(fi−1,w+ci⋅di−1,j),fi−1,j+(di,j+ci)⋅(di−1,j+ci−1)−di,jdi−1,j)."

If the matrix is

+1 +1 -1

+1 -1 -1 (let k=2)

f[1] = (0,0,0)

f[2][2] = f[1][w]+c[2]*d[1][2] = 0+2*0 = 0 OR 0+2*1-0=2

f[2][2] = 2

But in the matrix

1 1 1

1 2 2

f[2][2] = 3

Shouldnt the transition be max(fi-1,w + ci.di-1,j + ci-1.di,w? How are we taking into account the '' ci-1.di,w '' term?

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

Is there a typo in solution for problem G?

Spoiler