当前位置:网站首页>【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;
}
边栏推荐
- Methods of adding centerlines and centerlines in SolidWorks drawings
- 运用tensorflow中的keras搭建卷积神经网络
- Parameter sniffing (2/2)
- Arcgis操作: 批量修改属性表
- Pytest learning - dayone
- Before joining the chain home, I made a competitive product analysis for myself
- Writing file types generated by C language
- Finally, there is no need to change a line of code! Shardingsphere native driver comes out
- MongoDB创建一个隐式数据库用作练习
- Garbage disposal method based on the separation of smart city and storage and living digital home mode
猜你喜欢

Programming features of ISP, IAP, ICP, JTAG and SWD

每周推荐短视频:L2级有哪些我们日常中经常会用到的功能?

ES类和对象、原型

ORM model -- creation and query of data records

Programming features of ISP, IAP, ICP, JTAG and SWD

Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software

对存储过程进行加密和解密(SQL 2008/SQL 2012)

ORM -- grouping query, aggregation query, query set queryset object properties

STM32 ADC and DMA
![[learning notes - Li Hongyi] Gan (generation of confrontation network) full series (I)](/img/94/b4df1ce2861a851fcd8de3e08540b0.png)
[learning notes - Li Hongyi] Gan (generation of confrontation network) full series (I)
随机推荐
柏拉图和他的三个弟子的故事:如何寻找幸福?如何寻找理想伴侣?
嵌入式背景知识-芯片
request对象对请求体,请求头参数的解析
Internship log - day04
STM32 Basics - memory mapping
【剑指Offer】42. 栈的压入、弹出序列
Postman tutorial - scripting
.NET配置系统
“十二星座女神降临”全新活动推出
运用tensorflow中的keras搭建卷积神经网络
网上可以开炒股账户吗安全吗
Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT
喜马拉雅网页版每次暂停后弹窗推荐下载客户端解决办法
Use of JSON extractor originals in JMeter
Postman interface test VII
学习记录——高精度加法和乘法
arcgis操作:dwg数据转为shp数据
fiddler-AutoResponder
【acwing】789. 数的范围(二分基础)
Please ask me a question. I started a synchronization task with SQL client. From Mysql to ADB, the historical data has been synchronized normally
