Problem link :SPOJ.com - Problem SGIFT
Code link:my code link >> Online Compiler and IDE - GeeksforGeeks
Constraints are till 10^9
I am facing problem in coordinate compression in fenwic tree .
Like example:10 30 20 10 50 20 20
STEP1: I FISRT SORTED THE ARRAY :10 10 20 20 20 30 50
STEP2: I compressed it as 1 1 2 2 3 5 (10>1, 20>2 ,30>3, 50>4) with help of map in c++;
means new value for arr[i] = map[arr[i]] and I am updating BIT tree at index map[arr[i]] with value arr[i].
PROBLEM : ocuurs when I get query l=20 and r =40 ( query in this range) >>>query(map[40] ) -query(map[20]-1)
map[40] is not defined above since I have not taken input in the array which will be problem .What to do now ???
DIAGRAM FOR IMAGINATION FOR THIS PROBLEM :
