The title of hangdian is also in reverse order. Its scale is much smaller than that of poj, so it does not need to be merged and direct brute force statistics are required.
This requires the smallest number of reverse orders. At the beginning, each sequence is re-computed using the merge statement. It is found that the time has timed out. Later, I checked the Report on other people's problem solving and found that the number of reverse orders that can be calculated from the beginning can be used. This question is special. The number of input N is 0 ~ N-1.
From this number hold [I] We can know that a Number smaller than it has hold [I], a number larger than it has a n-1-hold [I.
Every time hold [I] is put to the end, ANS = ANS-hold [I] + n-1-hold [I];
# include
# include
# include
# define Max 500005 using namespace STD; long TMP [Max]; long hold [Max]; long long array [Max]; long ans; int num [Max]; int main () {int N; while (CIN> N) {for (INT I = 0; I
array [J]) num [I] ++; ans + = num [I];} long long _ min = ans; For (INT I = 0; I
ans) _ min = ans;} cout <_ min