第四个点MLE何解,求带师指点
查看原帖
第四个点MLE何解,求带师指点
675527
Play_CP_4fun楼主2022/5/6 00:52
#include <bits/stdc++.h>
using namespace std;
const int N = 5e6 + 10;
int n, ans, k, a[N];
void quick_sort(int a[], int l, int r) {
	if (l >= r) {
		ans = a[l];
		return;
	}
	
	int i = l, j = r, pivot = a[(l + r) / 2];
	while (i < j) {
		while (a[i] < pivot) i++;
		while (a[j] > pivot) j--;
		if (i < j) {
			swap(a[i], a[j]);
			i++;
			j--;
		}
	}
	
	if (k <= j) quick_sort(a, l, j);
	else if (k >= i) quick_sort(a, i, r);
	else quick_sort(a, j + 1, i - 1);
}
int main() {
	std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
	
	cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> a[i];
	quick_sort(a, 0, n - 1);
	cout << ans;
	return 0;
}

RT

2022/5/6 00:52
加载中...