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

Автор 055D, 6 лет назад, По-английски

Thank you for participating. I hope you enjoyed the contest!

1401A - Distance and Axis

Tutorial
Solution Code
Behind Story

1401B - Ternary Sequence

Tutorial
Solution Code
Behind Story

1401C - Mere Array

Tutorial
Solution Code
Behind Story

1401D - Maximum Distributed Tree

Tutorial
Solution Code
Behind Story

1401E - Divide Square

Tutorial
Solution Code
Behind Story

1401F - Reverse and Swap

Tutorial
Solution Code
Behind Story
Разбор задач Codeforces Round 665 (Div. 2)
  • Проголосовать: нравится
  • +221
  • Проголосовать: не нравится

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

Video Editorial of Problem C: Mere Array

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

Great problem set 055D!

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

In F, is solution O(n^2 q) solution supposed to fail? strict time limit :(

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

https://codeforces.me/contest/1401/submission/90613864

can someone tell the error in this solution....i think it has same idea as in editorial :(

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

Thanks for a good round and fast editorial!

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

Problems are too interesting...

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

Почему у авторов всегда такой говнокод?

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

Thanks a lot for the fast editorial 😀

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

055D I really liked your round!

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

Editorial came quicker than most people solved the first question :P

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

Can someone tell me a testcase where my code for problem B is failing? https://codeforces.me/contest/1401/submission/90608794 Thankyou

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

Pretests are too strong..

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

Swapping problem A & C would be the correct easy to hard order xD.

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

Fast editorial !!!! Great problems specially D problem . Thanks codeforces community

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

In problem E:

"∙ When a segment intersects with two sides (facing each other) of the square, the number of pieces increases by one."

Doesn't the number of pieces in this case increase by two?

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

Can anyone help me?

My code for Problem D here(https://codeforces.me/contest/1401/submission/90610162)

Like editorial's method, I was trying to get answer. but i don't know why it does not work.

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

About E: in the editorial, is it segment tree or interval tree?

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

Can someone share his/her approach for solving problem E. The editorial is too breif for me.

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

:)

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

Very nice problems!

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

What's special in Pretest 5(Question number D). Can anybody provide a smaller test so that I can manually verify my code? My submission I had considered the case when m>n-1 too. Any help will be highly appreciated.

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

Ratings are calculated already , this contest is fast.

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

what is the wrong with my solution for D

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

B using recursion (when you don't want to use brain but want to do labour work) https://codeforces.me/contest/1401/submission/90623923

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

    This is written in your code"//.size() return unsigned int so never use i<v.size()-1 in loop"

    What is the risk of doing that ?

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

      I never thought someone will ask about the commented part.

      In some question, you have to loop till the third last character of string. So you will write i<s.size()-2 But when string size is 1, then s.size()-1 will give wrong result as .size() always give in unsigned int.

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

Really Enjoyed the contest man ! Keep up the great works 055D especially and all other co-ordinators too in general :)

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

Please somebody expalin me in more detail, how to prove that we should multiply numbers in both cases in exactly this way. Sorry for my English

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

During the contest I submitted solution for F and it passed pretests. But I quickly realized that it works in $$$O(2^n \cdot q)$$$, though it was easy to fix so it would work in $$$O(nq)$$$ and I resubmitted. But then I submitted initial slow solution after the end of the contest, and it passed systests! So I quickly hacked it 90619845 But I'm quite disappointed that systest didn't manage to break my initial slow solution(

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

The idea behind D was exactly same as 1280C - Jeremy Bearimy.

And thank you for the contest.

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

My poor puny brain still didn't understand problem A. Could anyone kindly explain a bit more as to why ans would be 0 or 1 in case of k<n ?

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

    When k is less than n, consider B is x distance left of A, then k = n — 2*x. So x = (k — n)/2. If if the difference is odd, you need to move 1 unit, otherwise, with 0 steps you can do it. Visualize it with an example and you might understand better.

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

Can anyone explain in Problem D, why should we do the "product of the number of vertices belonging to each of the two components divided when the ith edge is removed from the tree"? I understood that the edge removed will be visited that many times, but am not getting the intuition or reasoning behind that.

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

If you understand what is required in D, the implementation is not trivial, but still easy. So the tutorial should explain what is needed. Instead, the wording is even more bulky than the problem statement.

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

C can also be solved in segment tree 90626651

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

How to prove the equivalence of the two segments in Problem F?

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

In problem B: Ternary sequence, along with the pairs 1,0 0,2 2,1 , I am also maximising the pair 2,2 to decrease the pairing of 1,2. But I am getting wrong answer. Please explain.

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

wow fast editorial fast rating change.. thanks for fast

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

Can someone help me with a smaller test case which fails my submission 90615069. Or point the mistake?

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

https://codeforces.me/contest/1401/submission/90627708

can anyone please help me with this code getting WA in test case 5

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

Good problem set !! :)

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

You can find elaborate video solutions to A-E (not F) here if you like videos, timestamps are in the description

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

Though the problems were good. But It would have been much better if at least one sample tests was considering the case m>n-1

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

In problem D, can someone tell me why my solution fails, please? I checked all the common mistakes (modulo before sort, more factors than edges), it doesn't seem that I fall into any of those categories.

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

How not to mess up implementation of problem D today if you have one hour to solve it? I got the solution in 5 minutes but couldn't finish it You see my code during contest and after a slight change in it.

And tell me what improvement should I do, to not repeat them in future.

code during contest ->90617959

code after slight change -> 90630780

hoping someone will help me.

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

WA on test5 problem D .checked all common erros overflow,not taking mod for storing frequencies. D wa on test5

sorry didnt check properly.

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

For problem E, I used ordered_set, but the same logic as in the editorial but it doesn't seem to be working for large test cases. Code — here

Help would be appreciated.

Edit — Found ! Thanks !

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

Best codes written. Hats off to you brooooo. Other editorialists use dirty templates. Templates so dirty that no one is able to understand. Why don't they understand that it is difficultto read codes, when untidy templates are used. Thanks for giving such clean codes.

Thank you so much. Again thanks.

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

Can some one elaborate on the proof for the second case in problem D ? Why is it guaranteed that the n-1 primes that are obtained from [p 0 , p1 ,p2 ,p 3, ... , p n-1 * p n *....*p m-1 ] are the maximum group of primes that can be obtained? I can see why if there is no MOD taken, but shouldn't the mod make things different?

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

Any idea why does this code not work for D? Code

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

I think there is another interesting way to solve the problem F using a lazy segment tree. The idea is to maintain the "lazy array" as a "segment tree" and then, the querie 2 and 3 are equivalent to updates in a range in the "segment tree" and the others queries are normal ones in the lazy segment tree. You have to keep in mind that you obtain the values of the "lazy array" with the "segment tree" in every moment. This way you can even do queries of type 2 or 3 in a certain range of blocks. What I mean is that not only works for the whole blocks of subarrays (update in the whole block of subarrays), but for certain range of blocks of subarrays. The complexity is O(n^2*q). Anyway, nice problemset bro!.

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

My solution for E:

By Euler's polyhedron formula, we have $$$V-E+F=2$$$ in a planar graph. We want to compute the number of faces of our planar graph, excluding the outside of the square, which is $$$F-1 = E-V+1$$$. For each segment (including the edges of the square), let's suppose that it has $$$v$$$ vertices lying on it. Then it contributes $$$v-1$$$ edges. Summing over all segments, $$$E = \sum v-1 = 2V-n-m-4$$$, since each vertex lies on exactly two segments and there are $$$n+m+4$$$ segments. Thus, $$$F-1 = V-n-m-3$$$. Computing $$$V$$$ is easy using sweepline.

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

Humble Request. I am facing issue with understanding D problems how have we calculated no. of nodes in the separated component(d) of which we are calculating d*(N-d). Actually I did it using Dfs N-1 time on each node. I knew that it will give TLE. Whereas here it is done in one Dfs only. Can someone explain to me whether this is a general algorithm or anything like that or where can I learn it from more intuitively?

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

My solution to D is running well on pc but giving wrong answer when submitted. Can anybody help me please https://codeforces.me/contest/1401/submission/90616879

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

.-. does anyone think that problem C is easier than B?

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

Hindi Video Solution for Problem D 1401D — Maximum Distributed Tree Youtube Video Solution Link for Prolbem D (hindi)

please have a look

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

Nice problems

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

In Problem B, I am using the same logic, then why I am getting the wrong answer.. https://codeforces.me/contest/1401/submission/90655781

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

Can anyone help me in finding why my code is giving WA on testcase 5. I used dfs to find the subtree size of node i, for all i, 1<=i<=n. Then used that subtree size to find the number of times some edge contributes to the answer. Then used greedy to find the maximum possible answer, and it matches the approach of the editorial.

Here is my submission.

90656681

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

Can some body point out what's problem with my solution to Problem D.

upd- problem was taking mod before sorting resulted in wrong results. Refer to this

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

I got the thinking process of D but I am not able to prove it for $$$m \gt n-1$$$, someone please help in making the proof more simple. Thanks !

In particular I am not able to see why all the big primes will go to first weight and other all weights get only single primes...

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

    Let us consider $$$n$$$ weights and $$$m$$$ primes.

    I'm using 1-indexed arrays.

    We must take into account 2 facts.

    Let $$$W_i$$$ be the $$$i$$$th smallest weight, i.e. sorted in ascending order. Let $$$c_i$$$ be the coefficient of $$$W_i$$$. Let us prove $$$c_i \lt =c_j$$$ if $$$i \lt j$$$. We can swap any two coefficients and retain the total product. Let us assume $$$c_i \gt c_j$$$ and $$$i \lt j$$$. Then we can show $$$c_iW_i + c_jW_j \lt = c_jW_i + c_iW_j$$$. So it is optimal for $$$c_i$$$ to be non-decreasing.

    We can show that $$$c_iW_i + c_nW_n \lt = c_iW_i/k + kc_nW_n$$$ for some $$$k \gt 1$$$. So optimal structure has all primes in $$$c_n$$$, as each prime shift is essentially just substituting $$$k$$$ as $$$p$$$.

    But since we need to minimize the number of ones, we need to give some primes to the previous values. So it also obvious that if there is more than 1 prime on some $$$c_i$$$ for $$$i \lt n$$$, it is optimal to shift it to $$$c_n$$$.

    Let us say that we gave a prime $$$p_j$$$ such that there exists $$$p_k$$$ such that $$$p_j \gt p_k$$$ and $$$p_k$$$ is in $$$c_n$$$. It is optimal to swap $$$p_j$$$ and $$$p_k$$$ as shown in the previous equation, $$$k$$$ for this swap is $$$p_j/p_k$$$ which is greater than $$$1$$$. Therefore the mentioned structure is optimal.

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

Can someone help me with a more formal proof for E?

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

    Hi Aditya,

    Here is a semi-formal proof. I mixed in graph and non-graph words, and realised midway that we do not really need the terminology for the problem.

    For each of the intersection points of the line segments, and each of the "dangling" endpoints of a line segment, we put a vertex there. The edges between these vertices are naturally formed. This gives us a planar graph which is also connected, as each line segment has one endpoint on the outer square. This gives, by Euler's formula,

    V-E+F = 2. This 2 includes the outer, infinite face, so F_finite = 1+E-V.

    Now, consider a "dangling" vertex (that is, a leaf vertex). We can delete this vertex along with the edge joined to it. This does not change the answer, as removing it decreases E and V both by 1.

    Now, consider two "internal" line segments (that is, one of the line segments other than the segments of the outer square) that intersect. This intersection increases E by 2, but increases V only by 1.

    Also, consider a line that completely crosses the outer square. Such a line segment increases E by 3 and increases V by 2.

    Therefore, our answer is

    1 + (number of intersections amidst the internal lines) + (number of internal lines that completely cut through the outer square).

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

If anyone need detail explanation & implementation of D Here

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

In problem D can someone explain why we are multiplying the largest prime numbers together(the case when m > n-1)? How do we prove that this is the optimal way?

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

https://codeforces.me/contest/1401/submission/90678039 My E submission is failing on test 5 :( Could use some help :P

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

Could anyone help me with debugging my code submission for problem D https://codeforces.me/contest/1401/submission/90679884 failing on test case 5 ? It seems ok to me.

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

problem C(Mere Array) can be done in one for-loop instead doing much stuff as given in editorial my submission link - https://codeforces.me/contest/1401/submission/90681298

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

Can someone tell me why this solution is giving TLE test 5{question D}. https://codeforces.me/contest/1401/submission/90657948

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

E is easier than I thought. What a pity, I had silly trouble with problem D and did not have enough time for E :((

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

Here's a more straightforward approach for F:

Let's build a standard range sum Segment Tree. Aditionally, we will store which powers of 2 have been swapped (in a simple boolean array).

Note that a reverse operation of power $$$k$$$ is simply swapping of all powers $$$i$$$ such that $$$i \lt k$$$. We have now reduced the problem to just range-sum with updates and swaps.

Whenever you swap a certain size, just flip its value in the boolean array we created. Now, because a segment tree is based on dividing the array into segments of powers of two, it's pretty easy to perform the swaps. Let's say you have assigned children of node $$$p$$$ to be $$$2*p+1$$$ (left child) and $$$2*p+2$$$ (right child).

While traversing the segment tree for anything (updates or sums), you just need to flip the children if needed. That is, if the power of two that this node is responsible for is swapped, your left child will now be $$$2*p+2$$$ and right child will be the node $$$2*p+1$$$.

This is pretty straightforward, and only adds a couple of lines to your standard segment tree implementation. Handles swap queries in constant time, and the other two in $$$O(n)$$$.

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

    Nice approach!

    About: "Note that a reverse operation of power $$$k$$$ is simply swapping of all powers $$$i$$$ such that $$$i \lt k$$$". How did you notice this?

    Mmm I see, like it says in editorial reverse is doing xor with $$$2^k - 1$$$ and swap is doing xor with $$$2^k$$$. So $$$2^k - 1 = 2^0 \oplus 2^1 \oplus \ldots \oplus 2^{k-1}$$$.

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

      Maybe one of those things that just click :)

      I didn't think of the XOR approach explicitly as mentioned in the editorial (although it is pretty intuitive if you think about it). The equation you mentioned also makes sense.

      I initially tried to simplify the problem by only considering queries of one kind. Swapping seemed pretty easy to do with a segment tree, and naturally I realised that reverses are also just swaps!

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

    This is awesome. I was thinking on the same lines but just couldn't realize that reverse operation can be seen as swap.

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

There is a mistake in the editorial for F, $$$[l,r]$$$ should map to $$$[l\text{^}(x\&\text{~}(2^k-1)), r\text{^}(x\&\text{~}(2^k-1))]$$$ instead.

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

A very subtle mistake which can be done in the D question is that, while calculating the frequency of the edges, you might use modular multiplication, which will give the wrong answer, as very high edge frequency, under modulo might become somewhat lesser, and in the end when sorting the frequency array, it might be more towards the smaller side and hence answer obtained will be lesser than the actual answer.

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

Auto comment: topic has been updated by 055D (previous revision, new revision, compare).

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

What is wrong with my submission?

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

Once again,I'm very much willing to recommand my blog for the Chinese editorial

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

In que C, it is given that we can rearrange only if the gcd(a1,a2) is the minimum element but the tutorial says only being divisible by the minimum is enough, can someone explain??

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

Can anyone check my code of problem D 90800991 ?.Could you suggest how to overcome these type of errors while taking mod.

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

For Question E wouldn't the runtime complexity for a sweep algorithm using a segment tree set be O((m+n)*log(m+n)) instead of O(nlogn + mlogm)?

Suppose we are sweeping from left to right. Then we would need to stop at every x value that corresponds to {beginning of horizontal segment, end of horizontal segment, or a vertical segment}. This adds up to (2n+m).

And for the segment tree, if we were to use index compression, we would still have to include leaf nodes for both the y-values corresponding to horizontal segments and the top/bottom y-values for vertical segments to be able to efficiently obtain a range query. So this would add to (n+2m).

Another possible solution is to use an ordered set instead of a segment tree, and we would only store the y-values of active horizontal segments. And for every vertical segment we can perform the range query using lower and upper bound, which would be O(logm). But this would still lead to a runtime of O((n+m)*logm).

I'm mainly just thinking out loud here, but if anyone can confirm/refute what I have here your help would be greatly appreciated!

Edit: So I just realized that using lower and upper bound with an ordered set would require O(m) instead of O(logm) since finding the distance between two iterators in a data structure without random access is linear. So this would mean that the segment tree is the fastest option. But my point still stands that the time complexity is O((n+m)*log(m+n)).

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

055D
I wonder why you use for(;t--;) unusual isn't it? Is there any special reason? I have seen most of the people using while(t--).

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

Alternate O(nq) solution for F:

Make a standard RSQ segment tree. Define the 'level' of a node in the tree as log2(size of range covered by node). The level of the root is obviously n.

An operation "swap k" can be simulated by swapping the left child and right child of all nodes with level = (k+1).

An operation "reverse k" can be simulated by swapping the left and right child of all nodes with level <= k.

The swap and reverse operations can be done fast with a lazy propagation type optimisation. After this, it's just basic query and updates on a segment tree.

My code for this: https://codeforces.me/contest/1401/submission/92201994

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

EDIT: found the mistake

Help needed !

Can someone please help me find my mistake in problem E's solution? I have been stuck on it for many days now, so help would be much appreciated!

My WA submission: 92319896

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

the solution code of problem D can't pass the test case?????

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

Could someone tell me the error in 102290234 this code for problem d? I'm getting wrong answer on test 5

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

Let $$$q$$$ = 1e9 + 7. If I use w[i]%q instead of w[i] (that can be > q), I get a wrong answer on Testcase-5.

Can someone explain why that would happen, when $$$a*b$$$ % $$$q$$$ = $$$(a$$$%$$$q \cdot b$$$%$$$q)$$$ % $$$q$$$

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

In D ... do not use modulo while calculating wi.... because after sorting it will change the required order and will give WA