[USACO 2017DEC] Haybale Feast
[题目链接]
https://www.lydsy.com/JudgeOnline/problem.php?id=5142
[算法]
首先用RMQ预处理S数组的最大值
然后我们枚举右端点 , 通过二分求出合法的 , 最靠右的左端点 , 用这段区间的最大值更新答案 , 即可
时间复杂度 : O(NlogN)
[代码]
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 1e5 + ;
const int MAXLOG = ;
const LL INF = 1e18; int n;
LL m;
LL value[MAXN][MAXLOG];
LL F[MAXN] , S[MAXN]; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
inline LL query(int l,int r)
{
int k = (int)((double)log(r - l + ) / log(2.0));
return max(value[l][k] , value[r - ( << k) + ][k]);
} int main()
{ read(n); read(m);
for (int i = ; i <= n; i++)
{
read(F[i]);
read(S[i]);
value[i][] = S[i];
}
for (int i = ; i <= n; i++) F[i] += F[i - ];
for (int i = ; i < MAXLOG; i++)
{
for (int j = ; j + ( << i) - <= n; j++)
{
value[j][i] = max(value[j][i - ],value[j + ( << (i - ))][i - ]);
}
}
LL ans = INF;
for (int i = ; i <= n; i++)
{
int l = , r = i , pos = -;
while (l <= r)
{
int mid = (l + r) >> ;
if (F[i] - F[mid - ] >= m)
{
pos = mid;
l = mid + ;
} else r = mid - ;
}
if (pos == -) continue;
chkmin(ans,query(pos,i));
}
printf("%lld\n",ans); return ; }
[USACO 2017DEC] Haybale Feast的更多相关文章
- BZOJ5142: [Usaco2017 Dec]Haybale Feast(双指针&set)(可线段树优化)
5142: [Usaco2017 Dec]Haybale Feast Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 182 Solved: 131[ ...
- BZOJ5142: [Usaco2017 Dec]Haybale Feast 线段树或二分答案
Description Farmer John is preparing a delicious meal for his cows! In his barn, he has NN haybales ...
- [USACO 08JAN]Haybale Guessing
Description The cows, who always have an inferiority complex about their intelligence, have a new gu ...
- [USACO 2017DEC] Barn Painting
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=5141 [算法] 树形DP 时间复杂度 : O(N) [代码] #include< ...
- [USACO 2017DEC] Greedy Gift Takers
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=5139 [算法] 二分答案 时间复杂度 : O(NlogN^2) [代码] #incl ...
- P4085 [USACO17DEC]Haybale Feast
我又开始水了,感觉又是一道虚假的蓝题 题意 非常好理解,自己看吧 题解 可以比较轻易的发现,如果对于一段满足和大于等于 \(m\) 的区间和其满足和大于等于 \(m\) 的子区间来说,选择子区间肯定是 ...
- Luogu4085 [USACO17DEC]Haybale Feast (线段树,单调队列)
\(10^18\)是要long long的. \(nlogn\)单调队列上维护\(logn\)线段树. #include <iostream> #include <cstdio> ...
- USACO 2015 December Contest, Gold Problem 2. Fruit Feast
Problem 2. Fruit Feast 很简单的智商题(因为碰巧脑出来了所以简单一,一 原题: Bessie has broken into Farmer John's house again! ...
- USACO . Your Ride Is Here
Your Ride Is Here It is a well-known fact that behind every good comet is a UFO. These UFOs often co ...
随机推荐
- 『NYIST』第八届河南省ACM竞赛训练赛[正式赛一]-CodeForces 237C,素数打表,二分查找
C. Primes on Interval time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Kubernetes网络设计原则
在配置集群网络插件或者实践K8S 应用/服务部署请时刻想到这些原则: 1.每个Pod都拥有一个独立IP地址,Pod内所有容器共享一个网络命名空间 2.集群内所有Pod都在一个直接连通的扁平网络中,可通 ...
- redis哨兵模式配置
java对redis的读写 依赖包:jedis.jar maven下: <!-- https://mvnrepository.com/artifact/redis.clients/jedis - ...
- msp430项目编程11
msp430中项目---步进电机控制系统 1.步进电机工作原理 2.电路原理说明 3.代码(显示部分) 4.代码(功能实现) 5.项目总结 msp430项目编程 msp430入门学习
- hdu6200 mustedge mustedge mustedge (并查集+dfs序树状数组)
题意 给定一个n个点m条边无向图(n,m<=1e5) 支持两个操作 1.添加一条边 2.询问点u到点v的所有路径中必经边的条数 操作数<=1e5 分析 第一眼看起来像是要动态维护无向图的边 ...
- Java实现简单的图片浏览器
第一次写博客,不喜勿喷. 最近一个小师弟问我怎么用Java做图片浏览器,感觉好久没玩Java了,就自己动手做了一下. 学校的教程是用Swing来做界面的,所以这里也用这个来讲. 首先要做个大概的界面出 ...
- Spring中使用存储过程
以下内容引用自http://wiki.jikexueyuan.com/project/spring/jdbc-framework-overview/sql-stored-procedure-in-sp ...
- Access to Image at 'file:///Users canvas本地图片跨域报错解决方案
1.设置跨域 添加跨域条件 crossorigin="anonymous" 前提是后端支持这个图片跨域 2.上面加了之后还是报错 如标题所示 你需要把你的项目放到服务器上面跑 ...
- 专题开发十二:JEECG微云高速开发平台-基础用户权限
专题开发十二:JEECG微云高速开发平台-基础用户权限 11.3.4自己定义button权限 Jeecg中.眼下button权限设置,是通过对平台自己封装的button标签(<t:dgFun ...
- [TypeScript] Transform Existing Types Using Mapped Types in TypeScript
Mapped types are a powerful and unique feature of TypeScript's type system. They allow you to create ...