当前位置:网站首页>【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;
}
边栏推荐
- fiddler-AutoResponder
- AI moves from perception to intelligent cognition
- Deconvolution popular detailed analysis and nn Convtranspose2d important parameter interpretation
- LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
- The method of word automatically generating directory
- Bit operation ==c language 2
- Postman interface test II
- conda离线创建虚拟环境
- 【ORM框架】
- uboot机构简介
猜你喜欢
ISP、IAP、ICP、JTAG、SWD的编程特点
官媒关注!国内数字藏品平台百强榜发布,行业加速合规健康发展
Enterprise practice | construction of banking operation and maintenance index system under complex business relations
Guide de signature du Code Appx
Memory ==c language 1
对存储过程进行加密和解密(SQL 2008/SQL 2012)
Word自动生成目录的方法
能源路由器入门必读:面向能源互联网的架构和功能
Inno Setup 打包及签名指南
Performance optimization record of the company's product "yunzhujia"
随机推荐
Using keras in tensorflow to build convolutional neural network
Why does the starting service report an error when installing MySQL? (operating system Windows)
对存储过程进行加密和解密(SQL 2008/SQL 2012)
Deadlock caused by non clustered index in SQL Server
Parameter sniffing (2/2)
Appx code signing Guide
能源路由器入门必读:面向能源互联网的架构和功能
ES6中的原型对象
Or in SQL, what scenarios will lead to full table scanning
ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
MCU与MPU的区别
STM32 ADC and DMA
Performance optimization record of the company's product "yunzhujia"
The story of Plato and his three disciples: how to find happiness? How to find the ideal partner?
【acwing】789. 数的范围(二分基础)
The method of word automatically generating directory
AI moves from perception to intelligent cognition
fiddler-AutoResponder
The Hal library is configured with a general timer Tim to trigger ADC sampling, and then DMA is moved to the memory space.
ISP、IAP、ICP、JTAG、SWD的编程特点