~~You take ~~Take a 2D BIT, and once the 2D array is converted to a 1D array and is sorted, for each element in the array, starting from the largest, ~~you would ~~add 1 to BIT [x][y], where x,y are the indices of the element in the original 2D array, after that you find the sum of the values in the BIT within the rectangle (0,0),(x,y), and add it to the answer. I'll tell you why this works, the conditions specified in the problem were : </br>1) x1 <= x2 </br>2) y1<=y2 </br>3) a[x2][y2] < a[x1][y1] </br> By adding the elements starting from the largest, you can say for sure, that any element whose coordinates have been recorded in the 2D BIT, is definitely larger than the current element that you have taken, that takes care of condition 3, and by taking the sum of the rectangle, you're making sure that the conditions 1 and 2 hold true.