标签:turn main scan stream span name nbsp ring 归并排序
#include<iostream> #include<cstdio> #include<cstring> using namespace std; long long a[101000],b[101000]; int n; inline void Merge(int l,int mid,int r) { for(int i=l;i<=r;i++) { b[i]=a[i]; } int ll=l; int rr=mid+1;; for(int i=l;i<=r;i++) { if(ll>mid) { a[i]=b[rr]; rr++; } else if(rr>r) { a[i]=b[ll]; ll++; } else { if(b[ll]<=b[rr]) { a[i]=b[ll]; ll++; } else { a[i]=b[rr]; rr++; } } } } inline void Mergesort(int l,int r) { if(l>=r) return; int mid=(l+r)>>1; Mergesort(l,mid); Mergesort(mid+1,r); Merge(l,mid,r); } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%lld",&a[i]); } Mergesort(1,n); for(int i=1;i<=n;i++) { printf("%lld ",a[i]); } return 0; }
标签:turn main scan stream span name nbsp ring 归并排序
原文地址:https://www.cnblogs.com/satans/p/11297335.html