1 条题解
-
0
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll P = 1e9 + 7; const int N = 5e6 + 5; int n,k, a[N]; void qsort(int l, int r) { // [l, r] = [l, j] + [i, r] if (l >= r) return; int i = l, j = r, base = a[l + r >> 1]; while (i <= j) { // [l,j] <= b, [i,r] >=b while (a[i] < base) i++; while (a[j] > base) j--; if (i <= j) swap(a[i], a[j]), i++, j--; } if(k <=j) qsort(l, j); if(k >=i) qsort(i, r); } int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", &a[i]); qsort(0, n-1); // sort(a, a+n); // nth_element(a, a+k, a+n); printf("%d", a[k]); return 0; }
- 1
信息
- ID
- 304
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 8
- 标签
- (无)
- 递交数
- 74
- 已通过
- 12
- 上传者