Hello, the contest Abacus'17 has just finished. Can somebody tell how to solve the problem, Geek Tree. asked 18 Mar '17, 00:01

try solving this https://www.hackerrank.com/challenges/similarpair answered 18 Mar '17, 01:59

This u can do easily bu using a dfs and BIT or segment tree.Basically as u go into a branch during dfs u update the node value in BIT.Then u do a search for all values in the range [sk,s+k] in the ancestors where "s" is the current node value because all those values will be counted as pairs with s. Here is when u will use BIT to find this value: ans+=query(s+k)query(sk1); U find this in O(log n).Then update this current node's value in BIT before going to its children. By doing this u can find the answer for all vertices and hence for the whole subtree. See my code for reference : https://www.codechef.com/viewsolution/13109792 Happy coding ;) answered 18 Mar '17, 00:50
Thanks although I don't know BIT or segment trees yet. So, I'll probably try this problem later.
(18 Mar '17, 01:06)
Can you please elaborate your answer? What will you get in ans after performing this query? And why there is a need of update in this offline query?
(18 Mar '17, 01:38)

Can someone tell the solution for this problem too : https://www.codechef.com/ABCS2017/problems/ABCS05 answered 18 Mar '17, 00:11

In this problem,try drawing a matrix to come up with a solution. You will observe a pattern. If u still can't figure it out, tell me and I'll tell u the full solution. answered 18 Mar '17, 00:21
