Блог пользователя LMydd0225

Автор LMydd0225, история, 2 года назад, По-английски

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
Разбор задач Codeforces Round 969 (Div. 1)
Разбор задач Codeforces Round 969 (Div. 2)
  • Проголосовать: нравится
  • +138
  • Проголосовать: не нравится

»
2 года назад, скрыть # |
Rev. 5  
Проголосовать: нравится -16 Проголосовать: не нравится

Congratulations Tourist for crossing 4000 rating!

»
2 года назад, скрыть # |
 
Проголосовать: нравится +97 Проголосовать: не нравится

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 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится -15 Проголосовать: не нравится

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

»
2 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится +2 Проголосовать: не нравится

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

»
2 года назад, скрыть # |
 
Проголосовать: нравится +22 Проголосовать: не нравится

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

»
2 года назад, скрыть # |
 
Проголосовать: нравится +45 Проголосовать: не нравится

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Probem A

void solve(int T)
{
    int a, b;cin>>a>>b;
    if(a&1)a--;
    cout<<(b-a+1)/4 <<endl;
}
»
2 года назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

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 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

nice set, liked Div1 A,B,C

»
2 года назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

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 года назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +12 Проголосовать: не нравится

    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 года назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

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 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 года назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 года назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

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

  • »
    »
    2 года назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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.

    • »
      »
      »
      2 года назад, скрыть # ^ |
      Rev. 2  
      Проголосовать: нравится 0 Проголосовать: не нравится

      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?

      • »
        »
        »
        »
        2 года назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится

        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 ):

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 года назад, скрыть # |
Rev. 4  
Проголосовать: нравится +4 Проголосовать: не нравится

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 года назад, скрыть # ^ |
    Rev. 3  
    Проголосовать: нравится +5 Проголосовать: не нравится

    $$$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 года назад, скрыть # ^ |
       
      Проголосовать: нравится -11 Проголосовать: не нравится

      how can you ignore the 1/2 part ?

    • »
      »
      »
      2 года назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

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

      • »
        »
        »
        »
        2 года назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится

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

      • »
        »
        »
        »
        2 года назад, скрыть # ^ |
         
        Проголосовать: нравится +11 Проголосовать: не нравится

        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.

»
2 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится +3 Проголосовать: не нравится

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 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 года назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

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 года назад, скрыть # |
 
Проголосовать: нравится +23 Проголосовать: не нравится

did anyone do B with segment tree + lazy propagation?

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

tourist orz

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 года назад, скрыть # |
 
Проголосовать: нравится -34 Проголосовать: не нравится

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 года назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

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?

  • »
    »
    2 года назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
2 года назад, скрыть # |
Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

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 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    2 года назад, скрыть # ^ |
     
    Проголосовать: нравится +8 Проголосовать: не нравится

    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.

    • »
      »
      »
      2 года назад, скрыть # ^ |
      Rev. 2  
      Проголосовать: нравится 0 Проголосовать: не нравится

      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!

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 .

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
»
23 месяца назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

I have an idea for problem B bonus:

My idea

How to solve it online?

  • »
    »
    23 месяца назад, скрыть # ^ |
     
    Проголосовать: нравится +5 Проголосовать: не нравится

    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.

»
11 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
8 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
4 недели назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Number Theory-forces