You are given an array of N integers With each integer a[I], call x is the number of integers before I and larger than a[I] Your task is find the sum of all x
If you know the solution, please give me some ideas about how to implement it. I have just started learning Segment Tree
You don't need segment trees for this. Here is my solution:
isn't this the same as counting inversions?
Yeah,u can use mergesort trees as well for this...
i understand the general idea, insert it into a set and find the iterator pointing to it. however, I don't get how you use the oset, template... can you explain how to manually code the order_of_key() function, if you can?
Well, I never looked into the source code for this, but if u simply want to use basic functionalities only, use the MergeSort tree methods from geeksforgeeks.
it's a red-black tree, a whole balancing binary tree that uses case forking as the main operator, that order of key function is something which uses a lot of pointer etc you can't just implement it randomly, you can either code the whole data structure or use merge sort:
There is also a way to count inversions using a segment tree, idk it
this won't work for duplicate occurances
nice, this'll work (but u need to insert {-x, i})
I changed the oset definition to use
greater
instead ofless