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

Автор antivenom, 11 лет назад, По-английски

Can anybody help me how to solve this question using segment tree.I am not getting what values should I maintain for nodes in order to get final result and how to merge them back to get parent of the childres etc.if possible please provide source code also.Thanks a lot

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

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

What you need to keep in a node is the amount of numbers in the interval that give remainders 0,1,2 respectively when divided by 3. Let those numbers be a0,a1,a2. The answer for a queried node will be a0. If a node needs to be updated, then we can simply shift the sequence a0,a1,a2 one position to the right. That is, it will become a2,a0,a1. Here is my code: http://ideone.com/rle8iQ :)

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

QSET try this :)