跳到正文

个人记录

nvdsajkfdvanbkjfd

hhsyh_0929约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年1月19日
收录
2025年12月12日
更新
2026年11月15日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n,a[N];
long long ans;
void quick_sort(int begin,int end){
	int l=begin,r=end,mid=a[(l+r)/2];
	ans+=mid;
	while(l<r){
		while(a[l]<mid)l++;
		while(a[r]>mid)r--;
		if(l<=r){
			swap(a[l],a[r]);
			r--,l++;
		}
	}
	if(begin<r)quick_sort(begin,r);
	if(l<end)quick_sort(l,end);
}
int main(){
	cin>>n;	
	for(int i=1;i<=n;i++)cin>>a[i];
	quick_sort(1,n);
	cout<<ans;
	return 0;  
}
	
原文