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

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

I am having problem understanding how we are utilising Binary Indexed tree to solve the problem.The DFS part is clear as well as the notion of levels. But i am unable to understand how BIT is used. http://codeforces.me/contest/383/problem/C link.

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

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

i solved it with segment tree . 1. find starting time and finishing time and also depth of each vertex with a dfs

  1. in segment tree interval of each vertex v with we do operation on it is [str[v] , fin[v]] because all of children of v have a starting time greater than v and finishing time less than v

  2. build 2 segment trees one for the ones with even depth and one for odd depth now when you r updating a vertex v you change intervals of one segment tree by +val and the other -val (just compare their depth mod 2)

  3. now for get queries just go throught every segment with vertex v in it and add it's value to answer !

check my code if u want (it's ugly :) ) http://codeforces.me/contest/383/submission/13809240