主页
题目
状态
排名
OI排名
统计
题解
请登录
常用链接
AOJ考试平台
老赵的Gitee代码
编译原理模拟考试平台
Java技术手册
FCC网站
菜鸟网
在线工具箱
字节豆包GPT
代码可视化
力扣网
牛客网
洛谷
杭电OJ
CodeForce
隐藏编译器
Problem F: 5_B : Merge Sort
上一题
正确率: $56.10\%$
下一题
Time Limit
$1$ 秒/Second(s)
Memory Limit
$512$ 兆字节/Megabyte(s)
提交总数
$41$
正确数量
$23$
"
裁判形式
标准裁判/Standard Judge
我的状态
尚未尝试
难度
分类标签
STL
×
为本题添加算法分类(请不要超过5个)
当前分类(单击移除):
STL
单击选择分类:
Description
<p> Merge Sort </p> <p> Write a program of a Merge Sort algorithm implemented by the following pseudocode. You should also report the number of comparisons in the Merge function. </p> <p> Merge(A, left, mid, right) </p> <p> n1 = mid - left; </p> <p> n2 = right - mid; </p> <p> create array L[0...n1], R[0...n2] </p> <p> for i = 0 to n1-1 </p> <p> do L[i] = A[left + i] </p> <p> for i = 0 to n2-1 </p> <p> do R[i] = A[mid + i] </p> <p> L[n1] = SENTINEL </p> <p> R[n2] = SENTINEL </p> <p> i = 0; </p> <p> j = 0; </p> <p> for k = left to right-1 </p> <p> if L[i] <= R[j] </p> <p> then A[k] = L[i] </p> <p> i = i + 1 </p> <p> else A[k] = R[j] </p> <p> j = j + 1 </p> <p> Merge-Sort(A, left, right){ </p> <p> if left+1 < right </p> <p> then mid = (left + right)/2; </p> <p> call Merge-Sort(A, left, mid) </p> <p> call Merge-Sort(A, mid, right) </p> <p> call Merge(A, left, mid, right) </p>
Input
In the first line n is given. In the second line, n integers are given.
Output
In the first line, print the sequence S. Two consequtive elements should be separated by a space character. In the second line, print the number of comparisons.
Sample Input
10 8 5 9 2 6 3 7 1 10 4
Sample Output
1 2 3 4 5 6 7 8 9 10 34
提示
<p> n ≤ 500000 </p> <p> 0 ≤ an element in S ≤ 10^9 </p>
登录后提交代码
题面与样例可直接查看,登录后即可在线提交和评测。
前往登录