当前位置:网站首页>【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;
}
边栏推荐
- 【acwing】786. 第k个数
- C logging method
- STM32 product introduction
- SolidWorks工程图中添加中心线和中心符号线的办法
- The new activity of "the arrival of twelve constellations and goddesses" was launched
- Win10安装VS2015
- Apprentissage avancé des fonctions en es6
- Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT
- ORM模型--关联字段,抽象模型类
- Word自动生成目录的方法
猜你喜欢
ArcGIS operation: converting DWG data to SHP data
ORM--查询类型,关联查询
[untitled]
Delete a record in the table in pl/sql by mistake, and the recovery method
高数_第1章空间解析几何与向量代数_向量的数量积
ISP、IAP、ICP、JTAG、SWD的编程特点
一文讲解单片机、ARM、MUC、DSP、FPGA、嵌入式错综复杂的关系
Performance optimization record of the company's product "yunzhujia"
LeetCode 练习——113. 路径总和 II
Arcgis操作: 批量修改属性表
随机推荐
ORM--查询类型,关联查询
Horizontal split of database
Appx code signing Guide
LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
大整数类实现阶乘
In addition to the objective reasons for overtime, what else is worth thinking about?
Introduction to energy Router: Architecture and functions for energy Internet
Do you have a boss to help look at this error report and what troubleshooting ideas are there? Oracle CDC 2.2.1 flick 1.14.4
CONDA creates virtual environment offline
Programming features of ISP, IAP, ICP, JTAG and SWD
Postman interface test V
Delete a record in the table in pl/sql by mistake, and the recovery method
Mongodb creates an implicit database as an exercise
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
Postman interface test IV
IPv4套接字地址结构
LeetCode 练习——113. 路径总和 II
ORM模型--数据记录的创建操作,查询操作
The landing practice of ByteDance kitex in SEMA e-commerce scene
The physical meaning of imaginary number J