当前位置:网站首页>【acwing】789. Range of numbers (binary basis)
【acwing】789. Range of numbers (binary basis)
2022-07-07 10:15:00 【percation】
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int a[N];
int n,q;
int main(){
scanf("%d%d",&n,&q);
for(int i = 0; i < n; i++){
scanf("%d",&a[i]);
}
while(q--){
int x;
scanf("%d",&x);
int l = 0, r = n - 1;
while(l < r){
int mid = l + r >> 1;
if(a[mid] >= x){
r = mid;
}
else{
l = mid + 1;
}
}
if(a[l] == x) cout << l <<" ";// Whether the element pointed to by the current pointer is equal to the queried element , If equal to, it means that the element exists , Returns the left endpoint of the element
else{
cout << "-1 -1" << endl;
continue;
}
l = 0, r = n - 1;// Determine the position of the right endpoint of the queried element
while(l < r){
int mid = (l + r + 1)>> 1;
if(a[mid] <= x){
l = mid;
}
else{
r = mid - 1;
}
}
cout << l << endl;
}
return 0;
}
边栏推荐
- Web3.0 series distributed storage IPFs
- Es classes and objects, prototypes
- Introduction to uboot
- ArcGIS operation: converting DWG data to SHP data
- Video based full link Intelligent Cloud? This article explains in detail what Alibaba cloud video cloud "intelligent media production" is
- conda离线创建虚拟环境
- Guid主键
- Before joining the chain home, I made a competitive product analysis for myself
- Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT
- Delete a record in the table in pl/sql by mistake, and the recovery method
猜你喜欢

Win10安装VS2015

柏拉图和他的三个弟子的故事:如何寻找幸福?如何寻找理想伴侣?

喜马拉雅网页版每次暂停后弹窗推荐下载客户端解决办法

Postman interface test VI

XML配置文件解析与建模

Es classes and objects, prototypes

Garbage disposal method based on the separation of smart city and storage and living digital home mode

ArcGIS operation: batch modify attribute table

LeetCode 练习——113. 路径总和 II

Pit encountered by vs2015 under win7 (successful)
随机推荐
Deadlock caused by non clustered index in SQL Server
“十二星座女神降临”全新活动推出
C#记录日志方法
ES类和对象、原型
Appx代碼簽名指南
Differences between MCU and MPU
Word自动生成目录的方法
SQLyog数据库怎么取消自动保存更改
Horizontal split of database
Video based full link Intelligent Cloud? This article explains in detail what Alibaba cloud video cloud "intelligent media production" is
Appx code signing Guide
Apprentissage avancé des fonctions en es6
STM32 Basics - memory mapping
request对象对请求体,请求头参数的解析
Pytest learning - dayone
The method of word automatically generating directory
Guid primary key
Official media attention! The list of top 100 domestic digital collection platforms was released, and the industry accelerated the healthy development of compliance
STM32 ADC和DMA
Garbage disposal method based on the separation of smart city and storage and living digital home mode
