快速排序应用
#include<bits/stdc++.h>
using namespace std;
#define cl(a,b) memset(a,b,sizeof(a))
#define LL long long
#define pb push_back
#define gcd __gcd
#define For(i,j,k) for(int i=(j);i<k;i++)
#define lowbit(i) (i&(-i))
#define _(x) printf("%d\n",x)
const int maxn = 1e6+10;
const int inf = 1 << 28;
LL a[maxn];
LL k;
int kth_sort(int l,int r){
//printf("l = %d, r = %d\n",l,r);
if(l>r){
if(a[l]==k)return l+1;
else return -1;
}
int low = l,high = r;
int key = a[l];//select the key
while(low<high){
while(low<high&&a[high]>key)high--;
a[low] = a[high];
while(low<high&&a[low]<=key)low++;
a[high]=a[low];
}
a[low] = key;
if(k<=key)kth_sort(l,low-1);
else kth_sort(low+1,r);
}
int main(){
int n;
while(~scanf("%d%lld",&n,&k)){
for(int i=0;i<n;i++){
scanf("%lld",&a[i]);
}
int ans = kth_sort(0,n-1);
printf("%d\n",ans);
}
return 0;
}