当前位置:网站首页>【acwing】786. Number k
【acwing】786. Number k
2022-07-07 10:15:00 【percation】
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int q[N];
int n,k;
int qs(int l, int r, int k){
if(l == r) return q[l];
int i = l - 1, j = r + 1, x = q[(l + r)/2];
while(i < j){
while(q[++i] < x) ;// Realize the left section to move forward to the right , The right section advances to the left
while(q[--j] > x) ;
if(i < j) swap(q[i],q[j]);
}
int s1 = j - l + 1;// Find the position of the dividing point in the interval at that time , Due to interval from 0 Start , So add 1
if(k <= s1)// When the number to be queried , When it is on the left of the current dividing point , Then left recursion , Otherwise, right recursion .
return qs(l, j, k);
return qs(j + 1,r, k - s1);
}
int main(){
scanf("%d%d",&n,&k);
for(int i = 0; i < N; i++){
scanf("%d",&q[i]);
}
cout << qs(0,n-1,k) << endl;
return 0;
}
边栏推荐
- Introduction to automated testing framework
- ISP、IAP、ICP、JTAG、SWD的编程特点
- How to cancel automatic saving of changes in sqlyog database
- uboot机构简介
- Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
- Agile course training
- Guide de signature du Code Appx
- Pytest learning - dayone
- [ORM framework]
- SQLyog数据库怎么取消自动保存更改
猜你喜欢
随机推荐
arcgis操作:dwg数据转为shp数据
Postman interface test IV
Finally, there is no need to change a line of code! Shardingsphere native driver comes out
Write it into the SR table in the way of flinksql. It is found that the data to be deleted has not been deleted. Refer to the document https://do
柏拉图和他的三个弟子的故事:如何寻找幸福?如何寻找理想伴侣?
Appx code signing Guide
The request object parses the request body and request header parameters
ORM model -- associated fields, abstract model classes
Inno Setup 打包及签名指南
request对象对请求体,请求头参数的解析
MCU is the most popular science (ten thousand words summary, worth collecting)
ORM -- query type, association query
Pytest learning - dayone
This article explains the complex relationship between MCU, arm, muc, DSP, FPGA and embedded system
【剑指Offer】42. 栈的压入、弹出序列
ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
The Himalaya web version will pop up after each pause. It is recommended to download the client solution
【HigherHRNet】 HigherHRNet 详解之 HigherHRNet的热图回归代码
[ORM framework]
Differences between MCU and MPU