当前位置:网站首页>【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;
}
边栏推荐
- ORM模型--数据记录的创建操作,查询操作
- ES6中的原型对象
- A wave of open source notebooks is coming
- C#记录日志方法
- 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
- The method of word automatically generating directory
- ORM--查询类型,关联查询
- The request object parses the request body and request header parameters
- IPv4套接字地址结构
- Postman tutorial - scripting
猜你喜欢
The landing practice of ByteDance kitex in SEMA e-commerce scene
ORM model -- creation and query of data records
Pdf document signature Guide
Postman interface test III
Appx代碼簽名指南
喜马拉雅网页版每次暂停后弹窗推荐下载客户端解决办法
ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
Bean 作⽤域和⽣命周期
HAL库配置通用定时器TIM触发ADC采样,然后DMA搬运到内存空间。
Guide de signature du Code Appx
随机推荐
Using keras in tensorflow to build convolutional neural network
Pytest learning - dayone
Or in SQL, what scenarios will lead to full table scanning
对存储过程进行加密和解密(SQL 2008/SQL 2012)
The request object parses the request body and request header parameters
Parameter sniffing (2/2)
ORM--逻辑关系与&或;排序操作,更新记录操作,删除记录操作
ES6中的原型对象
Win10 installation vs2015
能源路由器入门必读:面向能源互联网的架构和功能
Inno Setup 打包及签名指南
网上可以开炒股账户吗安全吗
Official media attention! The list of top 100 domestic digital collection platforms was released, and the industry accelerated the healthy development of compliance
【acwing】789. 数的范围(二分基础)
为什么安装mysql时starting service报错?(操作系统-windows)
【学习笔记-李宏毅】GAN(生成对抗网络)全系列(一)
ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
Future development blueprint of agriculture and animal husbandry -- vertical agriculture + artificial meat
Horizontal split of database
ORM--分组查询,聚合查询,查询集QuerySet对象特性