So I was trying to solve this programming problem.
Given an array of numbers and some queries. Each query gives you three numbers a,b,c and asks you to answer sum of all
sort queries according to c
sort array values in non-decreasing order
maintain (bit|segment tree) for storing range sum
before answering the current query, update index of all the array element whose value <= c
answer the range-query sum problem.
Time Complexity: (n+q)*log(n)
, space complexity: O(n)