Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=3743
The title is to give you a sequence of n, so you can ask for reverse order. I use merge sort to ask. Merge sort has a merging process, two paragraphs before and after, when A[i] > A[j], the description a[j] than the previous paragraph ah [i],a[i+1],a[i+2]....,a[mid] , which is smaller than these, so the total reverse logarithm to add mid-i+1.
1 //File Name:HDU3743.cpp2 //Author:xiaxiaosheng3 //Created time:2015 March 09 Monday 21:54 45 seconds4 5#include <vector>6#include <list>7#include <map>8#include <Set>9#include <deque>Ten#include <stack> One#include <bitset> A#include <algorithm> -#include <functional> -#include <numeric> the#include <utility> -#include <sstream> -#include <iostream> -#include <iomanip> +#include <cstdio> -#include <cmath> +#include <cstdlib> A#include <cstring> at#include <ctime> - - using namespacestd; - typedef __int64 INT; - Const intMAXN = 10e6+Ten; - in intN,A[MAXN],TEMP[MAXN]; - INT ans; to voidMerger (int*a,intSintMidinte) + { - intK =0, i = S,j = mid+1; the while(I <= mid && J <=e) * { $ if(A[i] <A[j])Panax Notoginsengtemp[k++] = a[i++]; - Else the { +Ans + = (mid-i+1); Atemp[k++] = a[j++]; the } + } - while(I <= mid) temp[k++] = a[i++]; $ while(J <= e) temp[k++] = a[j++]; $ for(inti =0; I < k;++i) -A[s+i] =Temp[i]; - } the voidMergersort (int*a,intSinte) - {Wuyi if(S <e) the { - intMid = (s + e)/2; Wu Mergersort (a,s,mid); -Mergersort (a,mid+1, e); About merger (A,S,MID,E); $ } - - } - intMain () { A while(SCANF ("%d", &n)! =EOF) + { the for(inti =0; I < n;++i) -scanf"%d",&a[i]); $Ans =0; theMergersort (A,0, N-1); theprintf"%i64d\n", ans); the } the return 0; -}
View Code
HDU 3743 Frosh Week (merging sort for reverse order)