[题目链接]

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的更多相关文章

  1. BZOJ5142: [Usaco2017 Dec]Haybale Feast(双指针&set)(可线段树优化)

    5142: [Usaco2017 Dec]Haybale Feast Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 182  Solved: 131[ ...

  2. BZOJ5142: [Usaco2017 Dec]Haybale Feast 线段树或二分答案

    Description Farmer John is preparing a delicious meal for his cows! In his barn, he has NN haybales ...

  3. [USACO 08JAN]Haybale Guessing

    Description The cows, who always have an inferiority complex about their intelligence, have a new gu ...

  4. [USACO 2017DEC] Barn Painting

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=5141 [算法] 树形DP 时间复杂度 : O(N) [代码] #include< ...

  5. [USACO 2017DEC] Greedy Gift Takers

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=5139 [算法] 二分答案 时间复杂度 : O(NlogN^2) [代码] #incl ...

  6. P4085 [USACO17DEC]Haybale Feast

    我又开始水了,感觉又是一道虚假的蓝题 题意 非常好理解,自己看吧 题解 可以比较轻易的发现,如果对于一段满足和大于等于 \(m\) 的区间和其满足和大于等于 \(m\) 的子区间来说,选择子区间肯定是 ...

  7. Luogu4085 [USACO17DEC]Haybale Feast (线段树,单调队列)

    \(10^18\)是要long long的. \(nlogn\)单调队列上维护\(logn\)线段树. #include <iostream> #include <cstdio> ...

  8. USACO 2015 December Contest, Gold Problem 2. Fruit Feast

    Problem 2. Fruit Feast 很简单的智商题(因为碰巧脑出来了所以简单一,一 原题: Bessie has broken into Farmer John's house again! ...

  9. 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 ...

随机推荐

  1. js清除非数字输入

    function clearNoNum(obj) { obj.value = obj.value.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符 ...

  2. hexo干货系列:(二)hexo主题下载及配置

    前言 上一篇文章介绍了hexo+gitHub简易搭建属于自己的个人独立博客,但是主题是默认的landscape,略显简单,今天的教程推荐Jacman主题. Jacman是一款为Hexo打造的一款扁平化 ...

  3. percona-toolkit工具安装

    1.yum安装 yum install perl-TermReadKey.x86_64 yum install perl-IO-Socket-SSL yum install perl-DBI.x86_ ...

  4. bzoj3637 CodeChef SPOJ - QTREE6 Query on a tree VI 题解

    题意: 一棵n个节点的树,节点有黑白两种颜色,初始均为白色.两种操作:1.更改一个节点的颜色;2.询问一个节点所处的颜色相同的联通块的大小. 思路: 1.每个节点记录仅考虑其子树时,假设其为黑色时所处 ...

  5. MTK andorid从底层到上层添加驱动

    1 [编写linux驱动程序] 1.1 一.编写驱动核心程序 1.2 二.配置Kconfig 1.3 三.配置Makefile 1.4 四.配置系统的autoconfig 1.5 五.编译 2 [编写 ...

  6. C#中将数字金额转成英文大写金额的函数

    <span style="white-space:pre"> </span>/// <summary> /// 数字转金额大写 /// 调用示例 ...

  7. Android Application基本组成部分

    Android Application基本组成部分 四个核心的组件 Activity活动,主要用于前台和用户交互,即UI,Activity只是加载一个View而并非一个UI对象 Service服务,主 ...

  8. php之ThinkPHP的memcached类的修改

    php之ThinkPHP的memcached类的修改 在Think\Cache\Driver\Memcached.class.php中,增加方法获取错误信息的方法,方便调试, public funct ...

  9. FATE---hdu2159(二重背包)

    FATE Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  10. 如何使用sqlalchemy获取某年某月的数据总和

    代码如下: # 基于Flask的SQLAlchemy # models class History(db.Model): __tablename__ = 'historys' id = db.Colu ...