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

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

Hello, at problem E last contest I have do segment tree and binary search which reach a good complexity O((n+q)log(maxY)log(n)) but i dont know why It just give me a TLE judgement on test 18 Maybe my poor implementation ? Or there's some infinite loop ? Or I just make a wrong calculation in complexity ? I still cant find my mistake so I hope u guy could help me. Here is my code: https://codeforces.me/contest/1440/submission/98824111 Thanks in advance.

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

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

I think your type 2 queries might be $$$\mathcal O(\log^2 n \log y)$$$.

while (pos <= n): This while loop executes $$$\log y$$$ times, once for each continuous segment.

first_small(pos,y), Get_pos(pos,y): Both of these seem to be $$$\log^2 n$$$ operations. They each have a $$$\log n$$$ while loop and call Get(1,1,n,pos,m) or Get(1,1,n,m,m) at each iteration, which is another $$$\log n$$$ operation.

To remedy this, replace Get(1,1,n,pos,m) or Get(1,1,n,m,m) by simply checking the sum of the subtrees in $$$\mathcal O(1)$$$ when deciding which children to traverse to.

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

    i got it,thank you so much for helping me. But i have use some technique called walk on tree. Is it what you mean ?

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

      Yes, I was describing walking down the tree in my last sentence :)