Binary Indexed Tree ,Segment Tree Probelm

Can any one help me how to solve CTRICK this problem using Binary Indexed Tree ,Segment Tree .