LMydd0225's blog

By LMydd0225, history, 20 months 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
  • +138
  • Vote: I do not like it

| Write comment?
»
20 months ago, hide # |
Rev. 5  
Vote: I like it -16 Vote: I do not like it

Congratulations Tourist for crossing 4000 rating!

»
20 months ago, hide # |
 
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!

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

    Hi LMydd0225, Can you define the function cntbit(int) used in the solution of Round 969 div1 problem C using sparse table

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

      There should be a definition for this at the beginning of the code.

      #define cntbit(x)   __buitin_popcount(x)
      

      It means the number of 1 bits in a number's binary form. For example, cntbit(10)=__builtin_popcount(10)=2, because $$$10_{10}=1010_2$$$

»
20 months ago, hide # |
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!

»
20 months ago, hide # |
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

  • »
    »
    20 months ago, hide # ^ |
     
    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.

    • »
      »
      »
      20 months ago, hide # ^ |
       
      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

      • »
        »
        »
        »
        20 months ago, hide # ^ |
         
        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.

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

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

»
20 months ago, hide # |
 
Vote: I like it +45 Vote: I do not like it

»
20 months ago, hide # |
 
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;
}
»
20 months ago, hide # |
 
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 :(

  • »
    »
    20 months ago, hide # ^ |
     
    Vote: I like it +4 Vote: I do not like it

    I think A was harder too.

  • »
    »
    20 months ago, hide # ^ |
     
    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 :( )

  • »
    »
    20 months ago, hide # ^ |
    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.

»
20 months ago, hide # |
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 ?

  • »
    »
    20 months ago, hide # ^ |
     
    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.

    • »
      »
      »
      20 months ago, hide # ^ |
       
      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.

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

nice set, liked Div1 A,B,C

»
20 months ago, hide # |
 
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)$$$

  • »
    »
    20 months ago, hide # ^ |
    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$$$.

»
20 months ago, hide # |
 
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.

»
20 months ago, hide # |
 
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

  • »
    »
    20 months ago, hide # ^ |
     
    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.

    • »
      »
      »
      20 months ago, hide # ^ |
       
      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

      • »
        »
        »
        »
        20 months ago, hide # ^ |
         
        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.

»
20 months ago, hide # |
 
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)?

»
20 months ago, hide # |
 
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?

  • »
    »
    20 months ago, hide # ^ |
     
    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.

    • »
      »
      »
      20 months ago, hide # ^ |
      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?

      • »
        »
        »
        »
        20 months ago, hide # ^ |
         
        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 \lt (n-1)d+1$$$, $$$n \gt \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 ):

»
20 months ago, hide # |
 
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.

»
20 months ago, hide # |
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) ?

  • »
    »
    20 months ago, hide # ^ |
    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.

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

      how can you ignore the 1/2 part ?

    • »
      »
      »
      20 months ago, hide # ^ |
       
      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

      • »
        »
        »
        »
        20 months ago, hide # ^ |
         
        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.

      • »
        »
        »
        »
        20 months ago, hide # ^ |
         
        Vote: I like it +11 Vote: I do not like it

        employed 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.

»
20 months ago, hide # |
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?)

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

    The bfs part can be replaced by loops : see 278873149

  • »
    »
    20 months ago, hide # ^ |
     
    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.

  • »
    »
    20 months ago, hide # ^ |
     
    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

    • »
      »
      »
      20 months ago, hide # ^ |
       
      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

»
20 months ago, hide # |
 
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

»
20 months ago, hide # |
 
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

»
20 months ago, hide # |
 
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).

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

did anyone do B with segment tree + lazy propagation?

  • »
    »
    20 months ago, hide # ^ |
     
    Vote: I like it +11 Vote: I do not like it

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

    https://mirror.codeforces.com/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

    • »
      »
      »
      20 months ago, hide # ^ |
       
      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.

      • »
        »
        »
        »
        20 months ago, hide # ^ |
         
        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.

  • »
    »
    20 months ago, hide # ^ |
    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

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

tourist orz

»
20 months ago, hide # |
 
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 :(

»
20 months ago, hide # |
 
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!

»
20 months ago, hide # |
 
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?

  • »
    »
    20 months ago, hide # ^ |
     
    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$$$.

»
20 months ago, hide # |
 
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

  • »
    »
    20 months ago, hide # ^ |
     
    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

»
20 months ago, hide # |
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?

»
20 months ago, hide # |
 
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)

  • »
    »
    20 months ago, hide # ^ |
     
    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} \lt x\le \frac{k}{i}$$$ in the range. When you solve a query, use prefix sums to find the $$$2\sqrt k$$$ elements.

    • »
      »
      »
      20 months ago, hide # ^ |
      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!

»
20 months ago, hide # |
 
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 .

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

I have an idea for problem B bonus:

My idea

How to solve it online?

  • »
    »
    19 months ago, hide # ^ |
     
    Vote: I like it +5 Vote: I do not like it

    Here's an online method (mainly about the (2) part in your idea):

    Let's consider $$$w(i,j)$$$: the number of not-covered edges on the path between node $$$i$$$ and the $$$2^j$$$-th ancestor of node $$$i$$$. $$$F(path)$$$ represents the number of not-covered edges on a path. It can be seen that $$$F(path)$$$ can be divided into sums of $$$O(\log n)$$$ different $$$w(i,j)$$$, and for each $$$j \gt 1$$$, $$$w(i,j)$$$ can be divided into sum of two $$$w(x,j-1)$$$. We want to know all the paths $$$x$$$ that $$$F(x)$$$ becomes $$$0$$$ after this update.

    $$$F(x)$$$ becomes $$$0$$$ if and only if the $$$w(i,j)$$$ it is divided into are all $$$0$$$. After we cover an edge ($$$x,fa_x$$$), first $$$w(x,0)$$$ becomes $$$0$$$, then it will affect some $$$w(y,1)$$$, and then $$$w(y,2)\dots$$$. However, it is meaningful to update the upper $$$w(x,y)$$$ values if only $$$w(i,j)$$$ becomes $$$0$$$. Thus there're only $$$O(n\log n)$$$ updates(Let $$$S_{x,y}$$$ represent the set of pairs $$$(i,j)$$$ that $$$w(i,j)$$$ can be divided into $$$w(x,y)$$$ and something else. When $$$w(x,y)=0$$$, do update on all elements in $$$S_{x,y}$$$). Then we can know all the paths that its weight will become 0 after the update.

    It seems a bit difficult to implement, so I didn't do that. I took the idea from NOI2024 D1T3, that is really similar and much more difficult, you can refer to this for further details.

    Btw, this solution can solve the problem that the $$$n$$$ paths are not $$$(i,(i\bmod n)+1)$$$, but can be the $$$m$$$ given special paths, online.

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

"If you can perform an operation that decreases a or b from an element, will it be different?" what the fuck does that even mean, get somebody write intelligible english tutorials for fucks sake

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

hello, soo i was just messing around and decided to submit the F 2006F - Dora's Paint of this contest. since im barely a pupil idk anything soo i just copied the editorial code and submitted and it seems to be failing on test 74. method 1 code 345156015 is failing on test 74, while method 2 code 345155433 works correctly and gives ac. idk why this is happening but can anyone pls look into it?? sorry to disturb you sir,LMydd0225 but can you pls take a look? thank you sir

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

I have some comments for div2D. I think this statement is somewhat imprecise: "The first to colour the root may lose the advantage of being the first (and when there are odd numbers of ? in the initial leaf nodes, Iris will colour one node less)" You lose advantage if you're the first to colour any of root+leaves (if you (I or D) colour leaf first, enemy could steal it from you by painting root in same/opposite colour). The optimal strategy once root colour gets determined is to paint leafs in alternating order (the one, who starts to paint leafs has advantage if their count is odd, in case of even number, I think 1st turn can be skipped when root is painted (instead paint unused unimportant one), but it doesn't matter as there's nothing better what can be done). So both players try to avoid starting to paint root+leaves and colour unimportant nodes. If their count is odd (I,D,I,...), D will be forced to start painting "important" ones. Another note is that no player will paint >=1 leaves first before root is coloured as rival can take over (switch colours, take winning one by painting root in opposite or same, depending on player).

"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), which will cause Iris to colour the leaves first." This is inaccurate as well IMO, D is free to colour leaf instead, but because of argument above, it can be stolen by I (same result though if D painted root).

"When Dora colours a leaf, Iris can colour another leaf with the opposite colour if there is at least one leaf left; and colour the root with the opposite colour if there is none left. " again, isn't it enough for I to fix colour opposite to D first turn as a root (can look to this situation as max(x,y) case when x!=y in code)? This will produce same result.