当前位置:网站首页>【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;
}
边栏推荐
- ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
- STM32 ADC and DMA
- There is a problem using Chinese characters in SQL. Who has encountered it? Such as value & lt; & gt;` None`
- Guide de signature du Code Appx
- .NET配置系统
- Can I open a stock trading account online? Is it safe
- Appx code signing Guide
- ORM--逻辑关系与&或;排序操作,更新记录操作,删除记录操作
- 官媒关注!国内数字藏品平台百强榜发布,行业加速合规健康发展
- STM32中AHB总线_APB2总线_APB1总线这些是什么
猜你喜欢

Inno setup packaging and signing Guide

嵌入式背景知识-芯片

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

AHB bus in stm32_ Apb2 bus_ Apb1 bus what are these

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

Web3.0 series distributed storage IPFs

ES类和对象、原型

How to cancel automatic saving of changes in sqlyog database

Postman interface test II

Chris Lattner, père de llvm: Pourquoi reconstruire le logiciel d'infrastructure ai
随机推荐
Before joining the chain home, I made a competitive product analysis for myself
Future development blueprint of agriculture and animal husbandry -- vertical agriculture + artificial meat
LLVM之父Chris Lattner:為什麼我們要重建AI基礎設施軟件
位操作==c语言2
conda离线创建虚拟环境
ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
web3.0系列之分布式存储IPFS
LeetCode 练习——113. 路径总和 II
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
AHB bus in stm32_ Apb2 bus_ Apb1 bus what are these
Guide de signature du Code Appx
高数_第1章空间解析几何与向量代数_向量的数量积
Methods of adding centerlines and centerlines in SolidWorks drawings
[ORM framework]
The physical meaning of imaginary number J
Official media attention! The list of top 100 domestic digital collection platforms was released, and the industry accelerated the healthy development of compliance
Postman interface test V
Finally, there is no need to change a line of code! Shardingsphere native driver comes out
The request object parses the request body and request header parameters
Parameter sniffing (1/2)
