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

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

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
  • Проголосовать: не нравится

»
6 лет назад, скрыть # |
← 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.