当前位置:网站首页>Acwing 787. Merge sort
Acwing 787. Merge sort
2022-06-13 09:25:00 【Age worry】
787. Merge sort
subject :
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int n,a[N],m;
void sort1(){
sort(a,a+n);
}
void sort2(int l,int r){
if(l>=r) return;
int mid=(l+r)>>1;
//cout<<mid<<endl;
sort2(l,mid);
sort2(mid+1,r);
int t[N],k=0;
int i=l,j=mid+1;
for(;i<=mid && j<=r;){
if(a[i]<=a[j]) t[k++]=a[i++];
else t[k++]=a[j++];
}
while(i<=mid) t[k++]=a[i++];
while(j<=r) t[k++]=a[j++];
for(int i=0;i<k;i++){
a[l+i]=t[i];
}
}
void sort3(int l,int r){
if(l>=r) return ;
int i=l-1,j=r+1,x=(l+r)>>1;
while(i<j){
do i++;while(a[i]<a[x]);
do j--;while(a[j]>a[x]);
if(i<j) swap(a[i],a[j]);
}
sort3(l,i);sort3(i+1,r);
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
//sort1();
sort2(0,n-1);
//sort3(0,n-1);
for(int i=0;i<n;i++)
printf("%d ",a[i]);
return 0;
}
边栏推荐
- Jenkins接入Openldap用户认证
- 20220606 Young's inequality for Matrices
- JUC原子数组
- Redis fuzzy query batch deletion
- LeetCode 6096. Success logarithm of spells and potions (binary search)
- BGP 联邦+Community
- C language: Simulated Implementation of library function strcpy
- LeetCode 6096. 咒语和药水的成功对数(二分查找)
- Yolov5 face video stream
- 【最全面详细解释】背包问题详解
猜你喜欢

Exploitation of competitive loopholes in attacking and defending world PWN play conditions

(state compression dp+good) acwing 291 Mondrian's dream

线上调试工具Arthas高级

Jenkins接入Openldap用戶認證

Storage mode of drawings

JUC atomic reference and ABA problem

SQL ROW_ The number() function uses
![1-4 message passing interface [CSP authentication]](/img/db/aecda548693cdfb0e740bcf1a1c823.jpg)
1-4 message passing interface [CSP authentication]

Final principle

(tree DP) acwing 285 A dance without a boss
随机推荐
Neo4j - CQL use
C language: summary of question brushing (1)
20211108 observable, controllable, stable and measurable
Batch read all voice files under the folder
JUC Unsafe
(dfs+ pruning + checkerboard problem +dood) acwing 843 N-queen problem
LeetCode 6095. 强密码检验器 II
LeetCode 5259. Calculate the total tax payable
C language: deep understanding of character functions and string functions (2)
I set up a blog
CAS无锁
C language time difference calculation
How to build an aby framework and run an instance
Jenkins集成Ldap,Ldap配置错误导致jenkins用户登录失败问题解决
C language: sanziqi
HAProxy + Keepalived实现MySQL的高可用负载均衡
Tutorial (5.0) 04 Fortint cloud services and scripts * fortiedr * Fortinet network security expert NSE 5
Yolov5 face learning notes
JUC 字段更新器
[implementation of depth first search]