当前位置:网站首页>【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;
}
边栏推荐
- MCU is the most popular science (ten thousand words summary, worth collecting)
- The method of word automatically generating directory
- Inno setup packaging and signing Guide
- 每周推荐短视频:L2级有哪些我们日常中经常会用到的功能?
- A wave of open source notebooks is coming
- STM32 product introduction
- Video based full link Intelligent Cloud? This article explains in detail what Alibaba cloud video cloud "intelligent media production" is
- ArcGIS operation: batch modify attribute table
- Pit encountered by vs2015 under win7 (successful)
- Future development blueprint of agriculture and animal husbandry -- vertical agriculture + artificial meat
猜你喜欢

Pytest learning - dayone

Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT

The physical meaning of imaginary number J

AI moves from perception to intelligent cognition

Inno Setup 打包及签名指南

Introduction to energy Router: Architecture and functions for energy Internet

HAL库配置通用定时器TIM触发ADC采样,然后DMA搬运到内存空间。

Postman interface test IV

“十二星座女神降临”全新活动推出

高数_第1章空间解析几何与向量代数_向量的数量积
随机推荐
ORM--数据库增删改查操作逻辑
Or in SQL, what scenarios will lead to full table scanning
虚数j的物理意义
Chris Lattner, père de llvm: Pourquoi reconstruire le logiciel d'infrastructure ai
柏拉图和他的三个弟子的故事:如何寻找幸福?如何寻找理想伴侣?
VS Code指定扩展安装位置
Why are social portals rarely provided in real estate o2o applications?
ORM -- query type, association query
Win10安装VS2015
Before joining the chain home, I made a competitive product analysis for myself
【剑指Offer】42. 栈的压入、弹出序列
LeetCode 练习——113. 路径总和 II
AHB bus in stm32_ Apb2 bus_ Apb1 bus what are these
Embedded background - chip
STM32产品介绍
中国首款电音音频类“山野电音”数藏发售来了!
ORM model -- associated fields, abstract model classes
This article explains the complex relationship between MCU, arm, muc, DSP, FPGA and embedded system
Postman interface test VI
China's first electronic audio category "Yamano electronic audio" digital collection is on sale!
