当前位置:网站首页>【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;
}
边栏推荐
- AHB bus in stm32_ Apb2 bus_ Apb1 bus what are these
- Deadlock caused by non clustered index in SQL Server
- Google colab loads Google drive (Google drive is used in Google colab)
- [ORM framework]
- Word自动生成目录的方法
- C logging method
- Analyze Android event distribution mechanism according to popular interview questions (I)
- Memory ==c language 1
- 位操作==c语言2
- Before joining the chain home, I made a competitive product analysis for myself
猜你喜欢
Chris Lattner, père de llvm: Pourquoi reconstruire le logiciel d'infrastructure ai
一文讲解单片机、ARM、MUC、DSP、FPGA、嵌入式错综复杂的关系
Pdf document signature Guide
HAL库配置通用定时器TIM触发ADC采样,然后DMA搬运到内存空间。
Official media attention! The list of top 100 domestic digital collection platforms was released, and the industry accelerated the healthy development of compliance
Methods of adding centerlines and centerlines in SolidWorks drawings
Use of JSON extractor originals in JMeter
STM32 ADC and DMA
ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
ISP、IAP、ICP、JTAG、SWD的编程特点
随机推荐
VS Code指定扩展安装位置
phpcms实现PC网站接入微信Native支付
Inno Setup 打包及签名指南
Appx code signing Guide
中国首款电音音频类“山野电音”数藏发售来了!
嵌入式背景知识-芯片
Postman interface test VII
STM32 ADC and DMA
Word自动生成目录的方法
ORM -- database addition, deletion, modification and query operation logic
Finally, there is no need to change a line of code! Shardingsphere native driver comes out
Interface test
ORM model -- associated fields, abstract model classes
uboot机构简介
web3.0系列之分布式存储IPFS
Future development blueprint of agriculture and animal husbandry -- vertical agriculture + artificial meat
Introduction to energy Router: Architecture and functions for energy Internet
ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
The Hal library is configured with a general timer Tim to trigger ADC sampling, and then DMA is moved to the memory space.
ORM--查询类型,关联查询