提交时间:2024-08-20 00:04:20

运行 ID: 168199

#include<bits/stdc++.h> using namespace std; long long a[1000005]; void f(int x,int y){ int mid,m,i,j; if(x>=y) return; i=x,j=y; srand((unsigned)time(NULL)); mid=a[y-rand()%(x-y)]; while(i<=j){ while(a[i]<mid){ i++; } while(a[j]>mid){ j--; } if(i<=j){ swap(a[i],a[j]); i++,j--; } } f(x,j); f(i,y); } int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); } f(1,n); for(int i=1;i<=n;i++){ printf("%d\n",a[i]); } return 0; }