Address: poj 2299
This afternoon's multi-school study does not seem to be done in vain... I am so bored that I learned how to sort together. Haha.
In simple terms, merging and sorting is actually dividing a binary tree into a single one, and then merging from the bottom layer in sequence. The reverse logarithm is in the process of merging, when the later section is bigger than him, all the later sections are bigger than him, all of which are reverse-order logarithm, so simply add them. I will not elaborate on the large amount of online materials .. With the idea of sub-governance.
The code written according to your understanding is too incomplete .. It took a long time to adjust...
The Code is as follows:
# Include <algorithm> # include <iostream> # include <cstring> # include <cstdlib> # include <cstdio> # include <queue> # include <cmath> # include <stack> # include <map> int A [6000000], CNT, C [6000000]; long K; void MERG (INT low, int mid, int high) {int I = low, j = Mid + 1; CNT = 0; while (I <= Mid & J <= high) {if (a [I]> A [J]) {c [CNT ++] = A [J ++]; k ++ = mid-I + 1 ;} else {C [CNT ++] = A [I ++] ;}} while (I <= mid) {c [CNT ++] = A [I ++];} wh Ile (j <= high) {C [CNT ++] = A [J ++];} CNT = 0; I = low; while (I <= high) {A [I ++] = C [CNT ++] ;}} void merger (INT low, int high) {int mid; If (low