Please read the new rule regarding the restriction on the use of AI tools. It applies starting from round 972. ×

LMydd0225's blog

By LMydd0225, history, 2 weeks ago, In English

2007A - Dora's Set

Hint 1
Hint 2
Hint 3
Tutorial
Implementation

2007B - Index and Maximum Value

Hint
Tutorial
Implementation

2007C - Dora and C++

Hint1
Hint2
Tutorial
Implementation

2006A - Iris and Game on the Tree

Hint1
Hint2
Hint3
Tutorial
Implementation

2006B - Iris and the Tree

Titbits
Hint1
Hint2
Tutorial
Implementation
Bonus

2006C - Eri and Expanded Sets

Hint1
Hint2
Hint3
Tutorial
Implementation - two pointers
Implementation - sparse table
Bonus

2006D - Iris and Adjacent Products

Hint1
Hint2
Hint3
Tutorial
Implementation

2006E - Iris's Full Binary Tree

Hint1
Hint2
Hint3
Hint4
Hint5
Tutorial
Implementation

2006F - Dora's Paint

Here're two methods. Method $$$1$$$ is my method, and method $$$2$$$ is some testers' method.

Method 1:

Hint1
Hint2
Hint3
Hint4
Hint5
Tutorial
Implementation - method 1

Method 2:

Hint1
Hint2
Hint3
Hint4
Tutorial
Implementation - method 2
  • Vote: I like it
  • +130
  • Vote: I do not like it

»
2 weeks ago, # |
Rev. 5   Vote: I like it -16 Vote: I do not like it

Congratulations Tourist for crossing 4000 rating!

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

    I created video editorial for Div2D/Div2A : Iris and Game on the Tree

    I created a hybrid video edtiorial and blog for Div2E/Div2B: Iris and the Tree.

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

      Thanks for the blog.. it helped me a lot in understanding some issues in my implementation.

»
2 weeks ago, # |
  Vote: I like it +97 Vote: I do not like it

Congratulations for tourist for reaching $$$4000$$$ rating, which is the highest rating on Codeforces ever! I'm proud to see that in my contest!

»
2 weeks ago, # |
Rev. 2   Vote: I like it -15 Vote: I do not like it

Thanks for the quick Editorial and congratulations for tourist for reaching $$$4000$$$ rating! I can't to believe that, but that's true!

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

Can someone suggest me what minor changes should be done in this submission-278848822 so that it passes 5th case without TLE !! Thanks

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

    Your solution's time complexity is O(m*n), which exceeds 10^8. Instead of updating the entire array, update only the maximum value as explained in the editorial.

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

    You are basically brute forcing on entire array for each operation. Basically you have time complexity of n*m. Instead there's a hack that you don't need to update whole array for each of m operations. Instead maintain a maximum element value and update it each time.

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

      Does brute-forcing every question is bad in long run?? Should i stop brute-forcing question focus more on optimizing the solution and writing it ?! Neerav03

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

        Yes, try to find out most optimal solution, codeforces except for initial problem A wants you to write most optimal code.

»
2 weeks ago, # |
  Vote: I like it +22 Vote: I do not like it

Instead of solving div1B I solved the bonus mid-contest O_O

»
2 weeks ago, # |
  Vote: I like it +45 Vote: I do not like it

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

Probem A

void solve(int T)
{
    int a, b;cin>>a>>b;
    if(a&1)a--;
    cout<<(b-a+1)/4 <<endl;
}
»
2 weeks ago, # |
  Vote: I like it +3 Vote: I do not like it

I can't believe i solved B with relative ease but took 4-5 attempts for A, am I the only one who found A that hard? :(

If i was able to solve A rather quickly I would have probably solved Div. 2 C for the first time :(

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

    I think A was harder too.

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

    I agree with you because I have spent 30 minutes on A but only 5 minutes on B (actually I do B before I do A, so much time penalty :( )

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

    Trying to solve problem A quickly, I made several trivial logical mistakes. Once I had the key idea of how gcd of consecutive numbers is 1, I started coding without careful thinking. It should have took me only a couple of minutes to reason the rest but instead, I coded a solution then tested it, wrong -> fix it again quickly -> compile and test -> wrong and so on about 5 cycles

    I think the best to do for me is to stop caring about rating and about solving a problem and just focus on learning something new from the process of trying to solve each problem.

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

    I found B to be harder lol. Got TLE in it, while I solved both A,C correctly. EDIT: Oh wait I retried the question and realised I messed up lol...B is much easier, I agree.

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

I have a very stupid question in problem C

Xa+yb = S
if(gcd(a,b)) == 1 
then there is a combination. 

but what if this combination has a negative number like X is negative then what ?

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

    Read Hint 1. As it is mentioned, if you add $$$a$$$ or $$$b$$$ to all the elements except $$$c_i$$$, it is the same as decreasing $$$a$$$ or $$$b$$$ from $$$c_i$$$. So it doesn't matter if $$$X,Y$$$ are negative.

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

      Can you please explain where did the idea of the GCD come from?

      I solved it using GCD but it was only a hunch and I can not prove anything.

      Thank you.

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

nice set, liked Div1 A,B,C

»
2 weeks ago, # |
  Vote: I like it +16 Vote: I do not like it

LMydd0225 In Div1 D, when you rewrite the condition as $$$cnt(1,i)\geq cnt(\dots,n)$$$ should not be $$$k$$$ instead? and second, array $$$[k,1,k]$$$ doesn't fullfill $$$cnt(1,1)\geq cnt(\frac{k}{2}+1,k)$$$

  • »
    »
    2 weeks ago, # ^ |
    Rev. 2   Vote: I like it +12 Vote: I do not like it

    Sorry, that's my fault. Updated.

    About the second question, I forgot that you should checkmin the two cnt values with $$$\lfloor\frac n2\rfloor$$$. It only goes wrong when $$$n$$$ is odd, $$$cnt(1,i)=\frac{n-1}2$$$, $$$cnt(\frac{k}{i+1}+1,k)=\frac{n+1}2$$$.

»
2 weeks ago, # |
  Vote: I like it +5 Vote: I do not like it

Wow, I had a way different solution for E.

What I wrote was, if I calculated the distance from each (i) to (i mod n + 1) and store it in an array to[i]. and they're all unassigned (We need to know the number of unassigned edges on every path)

Then each time I would assign a value to an edge, I would remove 1 from to[x-1] and remove 1 from to[mx[x]] where mx[x] is the max number the subtree at x reached.

Now the answer is Sum of assigned edges * 2 + (W — Sum of assigned edges) * Number of paths with unassigned edges

I kept and updated the number of unassigned edges of all paths in a segment tree.

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

can some one please point out in problem C why we need to try c2,c3,…cn as the minimum in turn.
I can't get it intuitively

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

    assume we have c1, c2, c3, c4, c5. After taking modulo of each, each number is <= gcd(a, b). Hence, adding d (i.e gcd(a, b)) to the current element makes it the largest. The next number therefore becomes the smallest in the list since we assumed that d was added to all previous numbers.

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

      I understand you but I can't see why we are doing this brute force thing I know that because it will lead to the best answer but I can't visualize it in my mind

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

        We want to eliminate the largest gap between the numbers

        if we have g =8

        c = 1 2 6 7 the largest gap is 4 between 2 & 6

        by increasing 1 & 2 we eliminated this gap and got

        6 7 9 10 which has an answer of 4 which is the best answer.

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

In the problem Div1 D, where it says cnt(k/(i+1)+1,n), shouldn't it be cnt(k/(i+1)+1,k)?

»
2 weeks ago, # |
  Vote: I like it +6 Vote: I do not like it

How do you solve the Div 1 C bonus? Is $$$k$$$ allowed to be non-integer?

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

    There're only $$$n\log V$$$ possible $$$\gcd$$$ over all $$$[l,r]$$$. Go over all the $$$\gcd$$$ from small to large, maintain the array $$$b_i=x$$$: the maximum $$$x$$$ that $$$\gcd_{i\dots x}\ge g$$$, where $$$g$$$ is the current gcd. There're only $$$n\log V$$$ updates. Use range sum queries to answer the queries.

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

      But $$$\frac{\max - \min + 1}{|Q(a_l\dots a_r)|}$$$ is not just a function of the gcd, how do you deal with that?

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

        Really sorry for that, it should be a typo: should be $$$(|Q|-1)k\ge \max-\min$$$.

        But I thought a while for the mistaken one: let $$$n=|Q|,d=\gcd$$$, then consider $$$nk<(n-1)d+1$$$, $$$n>\frac{d-1}{d-k}$$$. Let's take sth $$$B=\sqrt V$$$. Consider $$$\frac{d-1}{d-k}\le B$$$: the lower range for n is not high, so brute force it; otherwise, $$$d-k$$$ is not large, so brute force it. I can only solve it in $$$O(n\sqrt V\log)$$$ (or maybe $$$O(n\sqrt V\log^2)$$$ ?). There also seem to be something $$$O(V\log^{sth})$$$, but neither can fit the original constraints. Maybe it can be a not bad problem that $$$n,V\le10^5$$$. Anyway super sorry for the inconvenience ):

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

sth about Div1 B,feeling sick if not pouring it.

"For any vertex $$$i$$$ in the tree, there is an edge connecting..., with a weight equal to $$$t_i$$$.",

it seems like"for any vertex there is(/it has)a weight $$$t_i$$$",and easy to be mistaken,

(few read statement word by word to know your"with"refers to the"edge",especially there's formula making the sentence long,many just notice an edge,but I overlook it and wrongly focus on any vertex)

which is just what I'd consider in the contest and wastes half of my time to solve through the problems,

and of course annoying me a lot,not for my rating(dropped) but for the unsolving problems including C,D and maybe E.

To make it worse,there ISN'T ANY DEFINITION about the length of a simple path,the Note neither,so the participants like me may hard to find it when coding,only to find themselves not passing the examples.(on the condition that problems B,C,D are all easy)

As a CN CPer(you mentioned in the annoucement),I hate it badly,not intentionally to damage CN authors' impression,but I'd still say that,this is what CN rounds always happen,so I never intent to compete in any one of them,like some others.

as you see my English level is terrible with words ambiguous,and it doesn't mean this round is completely trash.After all,it really hurt me,and deepen the awful impression of CN rounds.

»
2 weeks ago, # |
Rev. 4   Vote: I like it +4 Vote: I do not like it

for problem C

"However, there's a better way to solve it. Similar to Euclidean Algorithm, the tolerance equals to the maximum odd divisor of the gcd of the difference array of a"

this came out of no where could you add more context please ?

also what is d in (c , d , len) ?

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

    $$$d$$$ should be the tolerance.

    About the gcd thing, you can consider merging two adjacent tolerances together: $$$a,b$$$ becomes $$$a,\frac{b-a}{2},\frac{a+b}{2}$$$. Ignore the $$$\frac 12$$$ stuff, and it's just the same reason as $$$\gcd(a,b)=\gcd(a,b-a)$$$. The whole process is similar to this.

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

      how can you ignore the 1/2 part ?

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

      Do you mind explaining intuitively why we are able to ignore the 1/2

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

        Refer to this. Actually I'm not good at explaining things clearly, sorry for that.

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

        Axial-Tilted This is the way I thought about it.

        • If the diff is divisible by 2 do it, so we remove all the multiple of 2 and care only about the remaining.
        • Now all the remaining diffs are both (odd and multiple of gcd).
        • Since nothing is divisible by 2 anymore the multiplier of gcd is not divisible by 2 (i.e gcd=3, and diffs will be (3*1, 3*3, 3*7, ...) and not 3*4 since this is even.
        • Now when you add the average we combine any two, both will have gcd as a common factor and the remaining will be (odd+odd).(i.e 3 * (1+3) or 3 *(3+7) the multiplier will be always even, so it will be divisible by 2 and create a small multiplier of gcd, and that will never go below the gcd since it's always a common factor and the multiplier is always divisible by 2, so the gcd will be the minimum gap we can get.

        Hope this clarifies your question.

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

Other solution for 1E:

I do not notice the movement way of the middle point of diameter. So I pre-calculated the answer for each point. It can be easily shown the optimal root is at most $$$O(logn)$$$ distance far from the middle point of diameter.Do a bfs starting at each point,and when you find a point degree $$$\le 2$$$,exit.Maintain such $$$O(logn)$$$ values during bfs : the maximum time the answer is smaller than $$$k$$$ for each $$$k$$$. Time should be $$$O(nlogn)$$$ ,not so sure about the complexity of the bfs part. submission: 278872280 (Maybe less data structure stuff?)

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

    The bfs part can be replaced by loops : see 278873149

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

    Time complexity of pre-calc is : O(sum of distance from each point to the nearest point with degree no more than 2).Can it be linear? the case of a perfect binary tree is $$$O(n)$$$.If so,1E can be solved in $$$O(n)$$$,using $$$O(n)$$$~$$$O(1)$$$ lca.

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

    I did the same observation of O(logn) distance from centre (it should be centre of diamater not centroid right?)

    You can then keep an iterative segment tree which will store the minimum depth of an "activated" node in your subtree. This solces in nlog^2 as you can query this data structure for centre, p[centre], p[p[centre]] and so on for log times

    This can be improved to nlogn by storing a frequency table f[i][j] = number of activated nodes in subtree of i at a distance j from it

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

      278842295 is the nlog^2, 278876918 is the nlog

      Funnily enough, the nlog^2 is faster

      Also author passed off the O(log) observation as trivial, but I would say it was the only non trivial part of this problem for me

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

I thought I understood how GCD works until I saw problem C. btw Chinese round = mathforce

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

THANK YOU note to organiser...

After reading the TITBITS section in 2006B question, I would like to admit that I wouldn't have been solve the 2006B, if you had used the "PREVIOUS VERSION" mentioned in editorial.

This statement is prime example of, How one statement can change the difficulty of the problem drastically.

cc : LMydd0225

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

There is another way (simpler, no need to discuss anything) to solve the case where the original state is already legal (based on method 2 in the editorial).

It's easy to observe that in this case all columns with the same number of $$$1$$$s in it are completely equivalent. Since the sum of $$$1$$$s is $$$m$$$, the number of essentially different columns is $$$O(\sqrt m)$$$. Therefore there are only $$$O(\sqrt m)$$$ essentially different operations to do.

For each operation, we can directly brute force and recalculate the contribution from scratch. Note that we only need the set of "the numbers of $$$1$$$s in a column", and how many times each element of the set appears in the originally array. The size of the set is also $$$O(\sqrt m)$$$, and each operation will modify this set by at most $$$O(1)$$$ elements, so each time we calculate the answer, the complexity is $$$O(\sqrt m)$$$, with a total complexity of $$$O(m)$$$. (If you are lazy, you can also do some sorting every time to avoid some discussion, with an additional $$$\log m$$$ to the complexity).

»
2 weeks ago, # |
  Vote: I like it +23 Vote: I do not like it

did anyone do B with segment tree + lazy propagation?

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

    You are not the only one brother. I also did it.

    https://codeforces.net/contest/2007/submission/278797086

    I wasted more than 25 minutes on this. I was surprised that SEG-with-LAZY is asked as B question.

    In first half an hour of the contest My rank was above 3500++ . After I solved D and E, I could recover. Also I am grateful that contest was for 2.5 hours instead of 2 hour. Otherwise, I would not have been able to solve E problem :P

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

      You used the intended solution and not segment tree. This means that you have no idea how you solved the problem, which points towards cheating. Please clarify below.

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

        I do not think this is cheating. It looks like he has some segment tree solution commented out. Perhaps he found the observation right as he was about to finish the segment tree code.

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

          Fair enough, but my concern is still valid though. Let's give him the benefit of the doubt then.

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

    IT tree for me is the correct solution. I think the tutorial is not concrete. Somehow they only consider the case where the initial max value is inside l, r. There is a test case that it can repeatedly update l r not containing the initial max for many times, and after that the new max appear. I would rate B is terrible

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

      but to go from max to max + 1, you must update the initial max

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

        you mean initial max or current max? for example, I have 2 elements array [10, 9], I update l =2, r = 2 twice to make 9 become 11, the initial max 10 is not considered

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

          $$$l=2,r=2$$$ changes nothing.It limits the value,not the position.

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

tourist orz

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

To solve Problem B in Division 1, my approach for addressing the bonus task, which involves counting adjacent pairs (x, x%n+1) where the nodes are on different sides of a given edge, is to use a persistent segment tree. The method involves the following steps:

  1. First, run a depth-first search (DFS) to obtain the DFS order of the nodes.

  2. For each node x in the DFS order, count how many nodes in its subtree have their LCA with x%n+1 that is positioned above the subtree of x.

I messed up this problem during the contest because I forgot the condition of first depth search that the problem is given :(

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

Problem B : Index and Maximum value

Video Editorial link: https://youtu.be/-vp9CdHeF6c?si=kuIEU6hnFIOSAyiN

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

Can someone please tell me from where should I study number theory for competitive programming ? I got stuck in question C of this contest.

»
2 weeks ago, # |
  Vote: I like it -34 Vote: I do not like it

Congratulations for tourist for reaching 4000 rating, which is the highest rating on Codeforces ever! I'm proud to see that in my contest!

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

For the problem div2D, can someone explain testcase 4 of example testcases. I did not quite understood this part from editorial: However, this can go wrong when there are equal numbers of 0 and 1 in the leaf nodes.

6
1 2
2 3
3 4
5 3
3 6
?0????

How is the answer 2 here?

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

    The first one to color the root or the leaf has disadvantage, so everyone tries to color the unimportant nodes first. So the process is: Iris sets $$$s_3=0/1$$$, Dora sets $$$s_1=0/1$$$, Iris sets $$$s_4=1-s_1$$$, Dora sets $$$s_5=s_1$$$, Iris sets $$$s_6=1-s_1$$$.

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

Can someone let me know why my submission is wrong? 278916361

What I am trying to achieve: In the line where I am printing the answer, I assume that (A.)the tree has the root node marked as 0 or 1 already and (B.)it is Iris's turn. So, the if statement before that tries to make some moves so that A and B conditions are satisfied.

However, this does not work, I replaced this block of code and it works now: 278980307. I do not know why did the previous submission fail

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

    In your previous submission, you forgot the following case: If there's only one question mark at the position of the root, you code processes the second step (made by Dora) even if it doesn't exist.

    1
    2 1
    1 2
    ?1
    

    correct: 1

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

Need help in Div.2 D

What is the proof of this part from the tutorial: "If there is an odd number of ? in the unimportant nodes, then Dora will have to colour the root (after filling the ? in the unimportant nodes one by one)"

Why Iris need odd number of ? in the unimportant nodes (not only one appearance of ? in an unimportant node) and why Dora has to fill the unimportant nodes one by one?

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

    The idea is basically that they mirror each other. They both don't want to color the root first but if there's an odd number of ? than Dora has to. You can watch Adaptatron's video for details.

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

Can anyone elaborate the approach using the Mo's algorithm for div1.D? (As the editorial mentioned)

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

    We need to maintain all the $$$cnt(1,i)$$$ and $$$cnt(\frac{k}{i+1}+1,k)$$$ stuff, $$$2\sqrt k$$$ elements in total, for each query. Using Mo's algorithm, after moving one of the pointers, you can only maintain the number of $$$x$$$ that $$$x=i$$$ or $$$\frac{k}{i+1}<x\le \frac{k}{i}$$$ in the range. When you solve a query, use prefix sums to find the $$$2\sqrt k$$$ elements.

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

      Oh I understand. I mistakenly think that I need to make a range modification and range query when moving the pointer, and I cannot figure out how to perform this $$$O(1)$$$.

      So we need to make a single point update on moving the pointer, and we can brute force calculate the prefix sum every time, which bring us a time complexity of $$$O\left(n\sqrt q + q\sqrt k\right)$$$, which can be further improved with decomposition, providing a $$$O\left(n\sqrt q + q\left(k^{1/4}+k^{1/2}\right)\right)$$$ complexity. (don't worth it though)

      Thank you for your elaboration!

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

You could use the Wikipedia link with the normal 'e' character. It loads the same page. https://en.wikipedia.org/wiki/Bezout's_identity

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

for DIV2E , my approch which i feel easy to implement ,

collect all edges wts and get the answer for this ,

now one by one try to remove edge wts .

see the effect of this on distances (whose sum needed) .

store the distances which pass through this edge wt , ( in future , if we remove some other weight , that weight can easily be added to these distances stored ) .

say , u are at some edge to remove it , now think of distances which pass through it , make sure that the distance does not belong to set (will consider separately ) . so say two or atleast one distance doesn't belong to set , for the pairs in the set now the delta in our answer is count of pairs * wt of this removed edge and the delta for the distances passing through this edges but not in the set is

cnt of the same * ( — this wt + sum of all removed weight including this wt as well ) — note that the cnt is the count of the distances (1 or 2 in number ) which are tightly packed with having no removed wts .

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

Is this not a simple edgecase for problem B:

1
5 5
1 2 3 4 5
+ 1 3
+ 1 3
+ 1 3
+ 1 3
- 4 5

??