当前位置:网站首页>Luogu p1816 loyalty solution
Luogu p1816 loyalty solution
2022-07-29 10:34:00 【q779】
Luogu P1816 loyal Answer key
Topic link :P1816 loyal
The question : Section min.
BIT The writing method is just for fun ( Actually not recommended )
There are some differences in inquiry ,
For example, if x-lowbit(x) Less than l l l , Then you cannot directly x-=lowbit(x)
Because this will put [ l , r ] [l,r] [l,r] Get something else in , So this part deals directly with violence
Unclear complexity , It should still be O ( log n ) O(\log n) O(logn)
Code :
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <random>
using namespace std;
#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
#define N (int)(1e6+15)
int n,m,a[N],tree[N];
int lowbit(int x){
return x&(-x);}
void update(int x,int v)
{
for(; x<=n; x+=lowbit(x))
tree[x]=min(tree[x],v);
}
int qMin(int l,int r)
{
int x=r,mn=INF;
for(; x>=l;)
{
if(x-lowbit(x)>l)
{
mn=min(mn,tree[x]);
x-=lowbit(x);
}
else mn=min(mn,a[x]),--x;
}
return mn;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen("check.in","r",stdin);
// freopen("check.out","w",stdout);
memset(tree,0x3f,sizeof(tree));
cin >> n >> m;
for(int i=1; i<=n; i++)
{
cin >> a[i];
update(i,a[i]);
}
for(int i=1,l,r; i<=m; i++)
{
cin >> l >> r;
cout << qMin(l,r) << ' ';
}
return 0;
}
Reprint please explain the source
边栏推荐
- Open source, compliance escort! 2022 open atom global open source summit open source compliance sub forum is about to open
- [semantic segmentation] 2021-pvt2 cvmj
- [Yugong series] go teaching course 010 in July 2022 - Boolean and character types of data types
- This developer, who has been on the list for four consecutive weeks, has lived like a contemporary college student
- 基于SSM实现高校后勤报修系统
- NUMA architecture CPU API change summary
- Data visualization design guide (information chart)
- Implementation of college logistics repair application system based on SSM
- Print out the "hourglass" and the remaining number according to the given number of characters and characters
- 学习R语言这几本电子书就够了!
猜你喜欢

若依集成minio实现分布式文件存储

电竞入亚后,腾讯要做下一个“NBA赛事捕手”?

mosquitto_ Sub -f parameter use

"Focus on machines": Zhu Songchun's team built a two-way value alignment system between people and robots to solve major challenges in the field of human-computer cooperation

Second handshake?? Three waves??

Oracle advanced (XIV) explanation of escape characters

【黑马早报】每日优鲜回应解散,多地已无法下单;李斌称蔚来将每年出一部手机;李嘉诚欲抄底恒大香港总部大楼;今年国庆休7天上7天...

【论文阅读】Q-BERT: Hessian Based Ultra Low Precision Quantization of BERT

Consumer electronics, frozen to death in summer

Object storage
随机推荐
R语言 使用数据集 veteran 进行生存分析
paho交叉编译
Second handshake?? Three waves??
[HFCTF 2021 Final]easyflask
通过tidymodels使用XGBOOST
使用R包skimr汇总统计量的优美展示
DW: optimize the training process of target detection and more comprehensive calculation of positive and negative weights | CVPR 2022
“为机器立心”:朱松纯团队搭建人与机器人的价值双向对齐系统,解决人机协作领域的重大挑战
MySQL optimization theory study guide
云服务大厂高管大变阵:技术派让位销售派
[paper reading] i-bert: integer only Bert quantification
电竞入亚后,腾讯要做下一个“NBA赛事捕手”?
【黑马早报】每日优鲜回应解散,多地已无法下单;李斌称蔚来将每年出一部手机;李嘉诚欲抄底恒大香港总部大楼;今年国庆休7天上7天...
HTB-AdmirerToo
消费电子,冻死在夏天
Kunlunbase support for MySQL private DML syntax
R 语言 二分法与 牛顿迭代法计算中方程的根
Docker installation, redis configuration and remote connection
This developer, who has been on the list for four consecutive weeks, has lived like a contemporary college student
Understanding of Arduino circuit