COMPCLUB TLE solution

I don’t know why i get TLE

queries to me is every node and its k and c

my approach:

1- make a tree for every club with dummy node root

2- sort queries by c(club) then k(level)

3- iterate over queries when a new club start i make dfs with InTime and OutTime for every node

4-Now easily get the sum of the k - 1 by segment tree and add the new sums to every node

code is here: http://ideone.com/UpAy43

i know there is editorial but i dont want to open it because if my approach have any wrong assumption to try again so please don’t say a new approach in comment just say to me why i get TLE

I did exaclty the same.


[1]

Since the intended solution is O(N) you need to implement this NlogN soln very carefully. Take care of using int rather than long long in unnecessary places. Such small optimizations will lead to AC

  [1]: https://www.codechef.com/viewsolution/14339427

and dont use seg tree. use BIT instead. The constant factor will reduce a lot.

//