I did this question using segment tree during the contest, got TLE.
I got this idea from here.
I guess my solution have following time and Space complexity:
update : (logN)^3 query : (logN)^3 space : 8*(8^log8(N))-1
According to the solution, the author gave 3-D BIT solution.
What is complexity of segment tree of update and query?