wyrqwq's blog

By wyrqwq, 5 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)

The editorial will be added soon.

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

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

Fun fact:

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

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

D was a cool one imo

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

C and D was difficult or I fckd up

  • »
    »
    4 hours 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.

    • »
      »
      »
      12 minutes ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it
      hint 1
      hint 2
      hint 3
      hint 4
      hint 5
      hint 6
»
16 hours 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.

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

    Are you sure your code is O(n)?

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

    Consider a tree with 1 internal node and n leaves.

    • »
      »
      »
      7 hours 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.

»
16 hours ago, # |
  Vote: I like it +9 Vote: I do not like it

Fast editorial forces

»
16 hours ago, # |
  Vote: I like it +69 Vote: I do not like it

predicting [800, 3000] for I is diabolical

»
16 hours ago, # |
  Vote: I like it +1 Vote: I do not like it

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

»
15 hours ago, # |
  Vote: I like it +11 Vote: I do not like it

I liked I1 very much, it was very fun

»
15 hours ago, # |
Rev. 3   Vote: I like it +402 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?

  • »
    »
    15 hours ago, # ^ |
    Rev. 2   Vote: I like it +68 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.

    • »
      »
      »
      15 hours ago, # ^ |
      Rev. 4   Vote: I like it +100 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 ...)

      • »
        »
        »
        »
        12 hours ago, # ^ |
        Rev. 2   Vote: I like it +8 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.

        • »
          »
          »
          »
          »
          10 hours ago, # ^ |
          Rev. 4   Vote: I like it +67 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.

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

            Yeah, that's a valid point.

        • »
          »
          »
          »
          »
          10 hours ago, # ^ |
            Vote: I like it +92 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.

          • »
            »
            »
            »
            »
            »
            9 hours ago, # ^ |
              Vote: I like it -37 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.

            • »
              »
              »
              »
              »
              »
              »
              86 minutes ago, # ^ |
                Vote: I like it +2 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.

    • »
      »
      »
      52 minutes ago, # ^ |
        Vote: I like it 0 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.

  • »
    »
    9 hours ago, # ^ |
      Vote: I like it +45 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.

»
15 hours ago, # |
  Vote: I like it +6 Vote: I do not like it

Overall a tough contest

»
15 hours ago, # |
  Vote: I like it 0 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!

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

    Consider a tree with 1 internal node and n leaves.

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

      Do you know where it specifically is getting TLE?

      • »
        »
        »
        »
        7 hours 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)$$$

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

Great round! Love it

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

Centroid decomposition for E 298885664 Can this be hacked?

»
15 hours 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.

  • »
    »
    5 hours 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]

    • »
      »
      »
      4 hours ago, # ^ |
        Vote: I like it 0 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]

»
15 hours ago, # |
  Vote: I like it +4 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

  • »
    »
    14 hours ago, # ^ |
      Vote: I like it +5 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

  • »
    »
    13 hours ago, # ^ |
      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
    • »
      »
      »
      11 hours 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 :(

      • »
        »
        »
        »
        4 hours 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.

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

      thank you very much!

»
15 hours 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.

  • »
    »
    15 hours 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?

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

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

    • »
      »
      »
      44 minutes 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.

»
15 hours ago, # |
  Vote: I like it +1 Vote: I do not like it

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

  • »
    »
    5 hours 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.

»
15 hours 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

  • »
    »
    15 hours 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

  • »
    »
    15 hours 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.

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

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

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

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

  • »
    »
    14 hours 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

    • »
      »
      »
      14 hours 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

»
14 hours 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.

  • »
    »
    5 hours ago, # ^ |
      Vote: I like it +1 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

»
14 hours ago, # |
Rev. 2   Vote: I like it +6 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}). $$$
»
14 hours 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??

  • »
    »
    12 hours 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).

»
14 hours 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

  • »
    »
    13 hours 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.

  • »
    »
    12 hours 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))

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

great round! better than goodbye 2023 :) ehehe

»
13 hours 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

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

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

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

      oh, that makes sense. thank you for the explaination

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

//

»
12 hours ago, # |
  Vote: I like it -56 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...

  • »
    »
    12 hours ago, # ^ |
      Vote: I like it +18 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.

    • »
      »
      »
      12 hours 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 ?

      • »
        »
        »
        »
        12 hours ago, # ^ |
          Vote: I like it 0 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

    • »
      »
      »
      12 hours ago, # ^ |
        Vote: I like it +3 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.

»
12 hours 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.

»
11 hours 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?

  • »
    »
    8 hours 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.

    • »
      »
      »
      6 hours 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?

      • »
        »
        »
        »
        25 minutes 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.

»
9 hours 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.

  • »
    »
    6 hours ago, # ^ |
      Vote: I like it +2 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

»
7 hours 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.

  • »
    »
    7 hours 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.

»
6 hours 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

»
4 hours 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..

»
4 hours 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)

»
4 hours 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 hours 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.

»
74 minutes 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";
»
67 minutes 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.