当前位置:网站首页>【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;
}
边栏推荐
- Deconvolution popular detailed analysis and nn Convtranspose2d important parameter interpretation
- ES6中的函数进阶学习
- STM32基础知识—内存映射
- Leetcode exercise - 113 Path sum II
- Performance optimization record of the company's product "yunzhujia"
- 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
- fiddler-AutoResponder
- Pytest learning - dayone
- This article explains the complex relationship between MCU, arm, muc, DSP, FPGA and embedded system
- Apprentissage avancé des fonctions en es6
猜你喜欢

【acwing】789. 数的范围(二分基础)

LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件

Inno setup packaging and signing Guide

ORM--数据库增删改查操作逻辑

Postman interface test V

Chris Lattner, père de llvm: Pourquoi reconstruire le logiciel d'infrastructure ai

This article explains the complex relationship between MCU, arm, muc, DSP, FPGA and embedded system

ES类和对象、原型

Use of JSON extractor originals in JMeter

Pytest learning - dayone
随机推荐
web3.0系列之分布式存储IPFS
Leetcode exercise - 113 Path sum II
Guys, have you ever encountered the case of losing data when Flink CDC reads mysqlbinlog? Every time the task restarts, there is a probability of losing data
ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
Pdf document signature Guide
Pytest learning - dayone
China's first electronic audio category "Yamano electronic audio" digital collection is on sale!
Horizontal split of database
VS Code指定扩展安装位置
【学习笔记-李宏毅】GAN(生成对抗网络)全系列(一)
Can I open a stock trading account online? Is it safe
中国首款电音音频类“山野电音”数藏发售来了!
[learning notes - Li Hongyi] Gan (generation of confrontation network) full series (I)
Analyze Android event distribution mechanism according to popular interview questions (I)
Performance optimization record of the company's product "yunzhujia"
Postman tutorial - scripting
.NET配置系统
Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT
【剑指Offer】42. 栈的压入、弹出序列
Word自动生成目录的方法
