Luogu4085 [USACO17DEC]Haybale Feast (线段树,单调队列)
\(10^18\)是要long long的。
\(nlogn\)单调队列上维护\(logn\)线段树。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Abs(a) ((a) < 0 ? -(a) : (a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long
#define ON_DEBUG
#ifdef ON_DEBUG
#define D_e_Line printf("\n\n----------\n\n")
#define D_e(x) cout << #x << " = " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt","r",stdin);
#else
#define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ;
#endif
struct ios{
template<typename ATP>ios& operator >> (ATP &x){
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x*= f;
return *this;
}
}io;
using namespace std;
const int N = 100007;
int n;
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
int t[N << 2];
inline void Pushup(int rt){
t[rt] = Max(t[rt << 1], t[rt << 1 | 1]);
}
inline void Updata(int rt, int l, int r, int x, int w){
if(l == r){
t[rt] = w;
return;
}
int mid = (l + r) >> 1;
if(x <= mid)
Updata(lson, x, w);
else
Updata(rson, x, w);
Pushup(rt);
}
inline int Query(int rt, int l, int r, int L, int R){
if(L <= l && r <= R){
return t[rt];
}
int mid = (l + r) >> 1, maxx = 0;
if(L <= mid) maxx = max(maxx, Query(lson, L, R));
if(R > mid) maxx = max(maxx, Query(rson, L, R));
return maxx;
}
long long sum[N];
int main(){
//FileOpen();
long long Val;
io >> n >> Val;
R(i,1,n){
int x, y;
io >> x >> y;
sum[i] = sum[i - 1] + x;
Updata(1, 1, n, i, y);
}
int ans = 2147483647;
int r = 1;
R(l,1,n){
while(r <= n && sum[r] - sum[l - 1] < Val) ++r;
if(r > n) break;
int newAns = Query(1, 1, n, l, r);
ans = Min(ans, newAns);
}
printf("%d", ans);
return 0;
}
Luogu4085 [USACO17DEC]Haybale Feast (线段树,单调队列)的更多相关文章
- 【BZOJ-2892&1171】强袭作战&大sz的游戏 权值线段树+单调队列+标记永久化+DP
2892: 强袭作战 Time Limit: 50 Sec Memory Limit: 512 MBSubmit: 45 Solved: 30[Submit][Status][Discuss] D ...
- BZOJ 1012 线段树||单调队列
非常裸的线段树 || 单调队列: 假设一个节点在队列中既没有时间优势(早点入队)也没有值优势(值更大),那么显然不管在如何的情况下都不会被选为最大值. 既然它仅仅在末尾选.那么自然能够满足以上的条件 ...
- POJ 2823 Sliding Window (线段树/单调队列)
题目不说了,可以用线段树或者单调队列,下面附上代码. 线段树: #include <iostream> #include <stdio.h> #include <algo ...
- bzoj 1171 大sz的游戏& 2892 强袭作战 (线段树+单调队列+永久性flag)
大sz的游戏 Time Limit: 50 Sec Memory Limit: 357 MBSubmit: 536 Solved: 143[Submit][Status][Discuss] Des ...
- 【BZOJ1171】大sz的游戏(线段树+单调队列)
点此看题面 大致题意: 有\(n\)个点,两点间最大通讯距离为\(L\).已知除\(1\)号点外第\(i\)个点能够发出和接收的信号区间\([l_i,r_i]\)以及到\(1\)号点的距离\(dis_ ...
- loj #6302. 「CodePlus 2018 3 月赛」寻找车位【线段树+单调队列】
考虑静态怎么做:枚举右边界,然后枚举上边界,对应的下边界一定单调不降,单调栈维护每一列从当前枚举的右边界向左最长空位的长度,这样是O(nm)的 注意到n>=m,所以m<=2000,可以枚举 ...
- Codevs 4373 窗口(线段树 单调队列 st表)
4373 窗口 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题目描述 Description 给你一个长度为N的数组,一个长为K的滑动的窗体从最左移至最右端,你只 ...
- 5.29 省选模拟赛 波波老师 SAM 线段树 单调队列 并查集
LINK:波波老师 LINK:同bzoj 1396 识别子串 不过前者要求线性做法 后者可以log过.实际上前者也被我一个log给水过了. 其实不算很水 我自认跑的很快罢了. 都是求经过一个位置的最短 ...
- BZOJ5142: [Usaco2017 Dec]Haybale Feast 线段树或二分答案
Description Farmer John is preparing a delicious meal for his cows! In his barn, he has NN haybales ...
随机推荐
- MUI+html5的plus.webview页面传值在电脑浏览器上不可见
使用plus.webview.currentWebview() 获得当前窗口的webview对象后,再使用document.write()输出显示webview的某个属性值,而plus.webview ...
- 纯CSS如何禁止用户复制网页的内容?
大家好,我是半夏,一个刚刚开始写文的沙雕程序员.如果喜欢我的文章,可以关注 点赞 加我微信:frontendpicker,一起学习交流前端,成为更优秀的工程师-关注公众号:搞前端的半夏,了解更多前端知 ...
- 深入浅出Nginx实战与架构
本文主要内容如下(让读者朋友们深入浅出地理解Nginx,有代码有示例有图): 1.Nginx是什么? 2.Nginx具有哪些功能? 3.Nginx的应用场景有哪些? 4.Nginx的衍生生态有哪些? ...
- 架构师必备:HBase行键设计与应用
首先要回答一个问题,为何要使用HBase? 随着业务不断发展.数据量不断增大,MySQL数据库存在这些问题: MySQL支持的数据量为TB级,不能一直保留历史数据.而HBase支持的数据量为PB级,适 ...
- Redis 中的原子操作(3)-使用Redis实现分布式锁
Redis 中的分布式锁如何使用 分布式锁的使用场景 使用 Redis 来实现分布式锁 使用 set key value px milliseconds nx 实现 SETNX+Lua 实现 使用 R ...
- 想知道Vue3与Vue2的区别?五千字教程助你快速上手Vue3!
从Vue3发布以来,我就一直对其非常感兴趣,就一直想着将其投入公司的生产中,但是开始考虑到很多不确定性就暂时对一些很小的功能进行一些尝试:慢慢的发现组合式Api的形式非常适合开发(个人感觉),尤其是V ...
- [安洵杯 2019]easy_web-1
1.首先打开题目如下: 2.观察访问的地址信息,发现img信息应该是加密字符串,进行尝试解密,最终得到img名称:555.png,如下: 3.获得文件名称之后,应该想到此处会存在文件包含漏洞,因为传输 ...
- SAP BPC 清除CUBE 中的数据
原理:先根据模型和查询条件取出数据,然后把金额设置为0,再写回CUBE. 1.获取数据并清空金额 *&--------------------------------------------- ...
- js 生成的html class属性失效问题
var html = '<fieldset class="struct-info" id="SlopeZY"><legend>变坡点(Z ...
- 关于android里activity之间利用button组件使用intent跳转页面
在需要跳转的activity 中 添加 Button button = findViewById(R.id.login);button.setOnClickListener(new View.OnCl ...