TRIPINV - Mega Inversions
The n^2 upper bound for any sorting algorithm
is easy to obtain: just take two elements
that are misplaced with respect to each other
and swap them. Conrad conceived an algorithm
that proceeds by taking not two, but three misplaced
elements. That is, take three elements
ai > aj > ak with i < j < k and place them in
order ak; aj ; ai. Now if for the original algorithm
the steps are bounded by the maximum number
of inversions n(n-1)/2, Conrad is at his wits' end as
to the upper bound for such triples in a given sequence. He asks you to write a program
that counts the number of such triples.
The rst line of the input is the length of the sequence, 1 <= n <= 10^5.
The next line contains the integer sequence a1; a2..an.
You can assume that all ai belongs [1; n].
Output the number of inverted triples.
3 3 2 1 Output: 2
I was the author of this problem back in 2011. The intended solution is using 2 BIT's, got Accepted with long longs.
Is using 2 segment trees TLE? Im getting TLE with segment trees, weird!Last edit: 2016-10-30 18:48:11
@Alex Abbas: Check if value added to BIT while updating is long long...I was getting WA because of this :)
Please tell me.
I think you mean decreasing subsequences.
for a more difficult version of this problem, try INCSEQ
why am i getting WA? is the result storable in long long int in c???
:-PLast edit: 2011-10-12 20:41:18