当前位置:网站首页>牛客小Bai月赛52 D 环上食虫(尺取+st表)
牛客小Bai月赛52 D 环上食虫(尺取+st表)
2022-06-29 17:47:00 【eva_can(not)survive】
登录—专业IT笔试面试备考平台_牛客网牛客网是互联网求职神器,C++、Java、前端、产品、运营技能学习/备考/求职题库,在线进行百度阿里腾讯网易等互联网名企笔试面试模拟考试练习,和牛人一起讨论经典试题,全面提升你的技术能力
https://ac.nowcoder.com/acm/contest/11229/D很明显题目说明是一个环,所以数组开两倍,然后通过双指针尺取区间,用st表预处理掉奶油的区间最大,尺取的时候需要注意边界,r-l需要小于等于n,要不然就会出现吃空气的情况从而使答案出现错误。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#define lowbit(x) ((x)&(-x))
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
const int MAXN=1e6+5;
const int INF=0x3f3f3f3f;
const ll NNF=0x3f3f3f3f3f3f3f3f;
int n;
ll s;
ll a[MAXN];
ll st[MAXN][24];
ll query(int x,int y){
int s=log2(y-x+1);
return max(st[x][s],st[y-(1<<s)+1][s]);
}
void solve(){
scanf("%d %lld",&n,&s);
for(int i=1;i<=n;i++) scanf("%lld",a+i);
for(int i=1;i<=n;i++) scanf("%lld",&st[i][0]);
for(int i=n+1;i<=2*n;i++){
a[i]=a[i-n];
// b[i]=b[i-n];
st[i][0]=st[i-n][0];
}
for(int i=1;i<=23;i++){
for(int j=1;j+(1<<i)-1<=2*n;j++){
st[j][i]=max(st[j][i-1],st[j+(1<<(i-1))][i-1]);
}
}
int l,r;
l=r=1;
ll sum=0;
// int mx=0;
ll ans=INF;
while(l<=r){
while(r<=2*n&&sum<s){
// mx=max(mx,a[r]);
sum+=a[r++];
}
while(r-l>n){
sum-=a[l++];
}
if(sum>=s){
ll mx=query(l,r-1);
ans=min(ans,mx);
}else if(r>2*n) break;
if(l<=r){
sum-=a[l++];
}
}
if(ans==INF) printf("-1");
else printf("%lld",ans);
}
int main(){
solve();
return 0;
}边栏推荐
- Walk with love, educate and run poor families, and promote public welfare undertakings
- OpenFeign使用步骤 轮询策略与权重 log4j使用 openFeign拦截器的配置
- How to solve the 2003 error of MySQL in Linux
- Basic operations such as MySQL startup under Windows platform
- reflex
- [网鼎杯 2020 青龙组]AreUSerialz
- The aggregate function in the epidisplay package of R language divides numerical variables into different subsets based on factor variables, and calculates the summary statistics and aggregate data. W
- MaxCompute Studio
- Does MySQL support foreign keys
- SRM supplier collaborative management system function introduction
猜你喜欢

与爱同行,育润走进贫困家庭,助推公益事业

Serial port experiment based on stm32f103zet6 library function

基于gis三维可视化的智慧城市行业运用

布隆过滤器:

SRM供应商协同管理系统功能介绍

Parental delegation mechanism

PCB frame drawing - ad19

DevCloud加持下的青软,让教育“智”上云端

Mysql database literacy, do you really know what a database is

How to solve MySQL 1045 error in Linux
随机推荐
What value can SRM systems bring to the enterprise?
阿里云不同账号新旧服务器镜像迁移数据迁移同步
Detailed introduction and Simulation of bitmap
R language ggplot2 visualization: use the patchwork package (directly use the plus sign +) to horizontally combine the two ggplot2 visualization results, and then horizontally combine them with the th
Digital twin energy system, creating a "perspective" in the low-carbon era
MATLAB 最远点采样(FPS)
Selenium key combination operation
MaxCompute Studio
3h精通OpenCV(八)-形状检测
R language uses GLM of mass package The Nb function establishes the negative binomial generalized linear model, and the summary function obtains the summary statistical information of the negative bin
selenium 文件上传方法
How to create a virtual image
Maidong Internet won the bid of Dajia Insurance Group
与爱同行,育润走进贫困家庭,助推公益事业
Li Kou today's question -535 Encryption and decryption of tinyurl
How MySQL queries character set codes of tables
Selenium upload file
Visual Studio插件CodeRush正式发布v22.1——优化调试可视化工具
PWM output experiment based on stm32f103zet6 library function
SRM供应商协同管理系统功能介绍