当前位置:网站首页>Niuke small Bai monthly race 52 D ring insectivorous (feet +st table)
Niuke small Bai monthly race 52 D ring insectivorous (feet +st table)
2022-06-29 17:56:00 【eva_ can(not)survive】
Sign in — major IT Written interview preparation platform _ Cattle from Niuke.com is the magic weapon of Internet Job Hunting ,C++、Java、 front end 、 product 、 Operational skills learning / Test preparation / Job search question bank , Online Baidu Alibaba Tencent Netease and other Internet famous enterprises written interview simulation test practice , Discuss the classic test questions with Niu Ren , Improve your technical ability in an all-round way
https://ac.nowcoder.com/acm/contest/11229/D Obviously, the title description is a ring , So the array is doubled , Then take the interval through the double pointer ruler , use st The table shows that the range of pretreated cream is the largest , When taking a ruler, you need to pay attention to the boundary ,r-l Need to be less than or equal to n, Otherwise, you will eat air and make the answer wrong .
#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;
}边栏推荐
猜你喜欢

Bloom filter:

Top 30 open source software

ISO 32000-2 国际标准7.7
![Fill in the next right node pointer of each node [make good use of each point - > reduce the space-time complexity as much as possible]](/img/33/bda0a898bfe3503197026d1f62e851.png)
Fill in the next right node pointer of each node [make good use of each point - > reduce the space-time complexity as much as possible]

kubekey2.2.1 kubernetes1.23.7离线包制作+harbor部暑并上传镜像

Detailed introduction and Simulation of bitmap

Bottom level internal skill cultivation

布隆过滤器:

Premature end of script headers 或 End of script output before headers

NVIDIA installs the latest graphics card driver
随机推荐
Force deduction daily question 06.29 add two numbers
Graduation season | Huawei experts teach interview tips: how to get a high salary offer from a large factory?
3h精通OpenCV(九)-最简单的人脸检测
PWM output experiment based on stm32f103zet6 library function
回文子串的最大长度(字符串哈希+二分)
剑指 Offer 13. 机器人的运动范围 (BFS)
位图的详细介绍及模拟实现
QQ如何开通在线客服
Bottom level internal skill cultivation
如何使用B/S开发工具DevExtreme的图表控件 - 自定义轴位置?
Segment tree and tree array template (copy and paste are really easy to use)
DevCloud加持下的青软,让教育“智”上云端
Selenium key combination operation
剑桥大学教授:经常吃早餐害处多,很危险 - 知乎
小程序容器是什么技术?能助力物联网企业红海突围?
图像特征计算与表示——基于内容的图像检索
剖析下零拷贝机制的实现原理,适用场景和代码实现
Does rapid software delivery really need to be at the cost of security?
DevCloud加持下的青软,让教育“智”上云端
自动化软件测试 - 利用短信转发器结合Selenium读取短信验证码