Cranker's blog

By Cranker, 9 years ago, In English

Hi I am currently trying to solve my first problem with segment tree. Link to the problem:http://www.hackerearth.com/tracks/pledge-2015-medium/xor-in-tree-1/

I couldn't understand the segment tree implementation in context to this problem which is present in the editorial in the problem setter's solution.

What does T[i] store here?

For the second query, why

int res = path_xor[u] ^ path_xor[v] ^ ST.get_xor(pos[u]) ^ ST.get_xor(pos[v]) ^ a[c];

and not

int res = ST.get_xor(pos[u]) ^ ST.get_xor(pos[v]) ^ a[c]; for the second query?

Currently, I could only understand that the tree is first ordered so that it becomes inline ie topological sort.Now the segment tree works on this topologically sorted tree.

Full text and comments »

  • Vote: I like it
  • +1
  • Vote: I do not like it

By Cranker, 9 years ago, In English

Hi This is my first post.I was trying to solve the Tree Coloring problem on hackerearth.com.

Problem Link:http://www.hackerearth.com/problem/algorithm/tree-coloring/

I'm having difficulty in understanding the editorial of the above problem.

Could somebody explain me why

F[i] = C(S[i], S[c_1]) * C(S[i]-S[c_1], S[c2]) * .. * C(S[i]-S[c_1]-S[c_2] — .. — S[c_(k-1)], S[c_k]) * F[c_1] * F[c_2] * .. *F[c_k], where C(n, k) denoting binomial coefficient (n, k), that means C(n, k) = n! / ((n-k)! * k!)?`

I was only able to understand the F[c_1] * F[c_2] * .. *F[c_k] part.

But was unable to understand the reason behind

C(S[i], S[c_1]) * C(S[i]-S[c_1],S[c2]) * .. * C(S[i]-S[c_1]-S[c_2]-S[c_(k-1)], S[c_k]).

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it