当前位置:网站首页>【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;
}
边栏推荐
- PDF文档签名指南
- Postman tutorial - scripting
- Apprentissage avancé des fonctions en es6
- 虚数j的物理意义
- Es classes and objects, prototypes
- 能源路由器入门必读:面向能源互联网的架构和功能
- Analyze Android event distribution mechanism according to popular interview questions (II) -- event conflict analysis and handling
- Why are social portals rarely provided in real estate o2o applications?
- Use of JSON extractor originals in JMeter
- ORM model -- associated fields, abstract model classes
猜你喜欢
fiddler-AutoResponder
Bean operation domain and life cycle
Pit encountered by vs2015 under win7 (successful)
Arcgis操作: 批量修改属性表
Deconvolution popular detailed analysis and nn Convtranspose2d important parameter interpretation
ORM -- database addition, deletion, modification and query operation logic
[ORM framework]
Bean 作⽤域和⽣命周期
ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
The request object parses the request body and request header parameters
随机推荐
对存储过程进行加密和解密(SQL 2008/SQL 2012)
Bean operation domain and life cycle
Bean 作⽤域和⽣命周期
The Hal library is configured with a general timer Tim to trigger ADC sampling, and then DMA is moved to the memory space.
flink. CDC sqlserver. You can write the DEM without connector in sqlserver again
单片机(MCU)最强科普(万字总结,值得收藏)
request对象对请求体,请求头参数的解析
Postman interface test III
arcgis操作:dwg数据转为shp数据
【HigherHRNet】 HigherHRNet 详解之 HigherHRNet的热图回归代码
Google colab loads Google drive (Google drive is used in Google colab)
A wave of open source notebooks is coming
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
Agile course training
Integer inversion
Postman interface test I
Appx code signing Guide
China's first electronic audio category "Yamano electronic audio" digital collection is on sale!
In addition to the objective reasons for overtime, what else is worth thinking about?
The story of Plato and his three disciples: how to find happiness? How to find the ideal partner?