题目链接:逆序数 模板题. #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i) #define lson i << 1, L, mid #define rson i << 1 | 1, mid + 1, R const int N = 100010; long long ans = 0; struct node{ int x…
#include <iostream> #include <cstring> using namespace std; ; int a[maxn]; int res[maxn]; int ans; //归并排序 void merge(int l, int r){ //cout<<l<<" "<<r<<endl; ; ; int cur = l; while (i <= mid && j <…
归并排序求逆序数 Time Limit:7000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Description In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjac…
int InversionNumber(char* s,int len) { int ans=0; //s逆序数 int A,C,G; //各个字母出现次数,T是最大的,无需计算T出现次数 A=C=G=0; for(int i=len-1;i>=0;i--) { switch(s[i]) { case 'A':A++;break; //A是最小的,无逆序数 case 'C': { C++; ans+=A; //当前C后面出现A的次数就是这个C的逆序数 break; } case 'G':…