\(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 (线段树,单调队列)的更多相关文章

  1. 【BZOJ-2892&1171】强袭作战&大sz的游戏 权值线段树+单调队列+标记永久化+DP

    2892: 强袭作战 Time Limit: 50 Sec  Memory Limit: 512 MBSubmit: 45  Solved: 30[Submit][Status][Discuss] D ...

  2. BZOJ 1012 线段树||单调队列

    非常裸的线段树  || 单调队列: 假设一个节点在队列中既没有时间优势(早点入队)也没有值优势(值更大),那么显然不管在如何的情况下都不会被选为最大值. 既然它仅仅在末尾选.那么自然能够满足以上的条件 ...

  3. POJ 2823 Sliding Window (线段树/单调队列)

    题目不说了,可以用线段树或者单调队列,下面附上代码. 线段树: #include <iostream> #include <stdio.h> #include <algo ...

  4. bzoj 1171 大sz的游戏& 2892 强袭作战 (线段树+单调队列+永久性flag)

    大sz的游戏 Time Limit: 50 Sec  Memory Limit: 357 MBSubmit: 536  Solved: 143[Submit][Status][Discuss] Des ...

  5. 【BZOJ1171】大sz的游戏(线段树+单调队列)

    点此看题面 大致题意: 有\(n\)个点,两点间最大通讯距离为\(L\).已知除\(1\)号点外第\(i\)个点能够发出和接收的信号区间\([l_i,r_i]\)以及到\(1\)号点的距离\(dis_ ...

  6. loj #6302. 「CodePlus 2018 3 月赛」寻找车位【线段树+单调队列】

    考虑静态怎么做:枚举右边界,然后枚举上边界,对应的下边界一定单调不降,单调栈维护每一列从当前枚举的右边界向左最长空位的长度,这样是O(nm)的 注意到n>=m,所以m<=2000,可以枚举 ...

  7. Codevs 4373 窗口(线段树 单调队列 st表)

    4373 窗口 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题目描述 Description 给你一个长度为N的数组,一个长为K的滑动的窗体从最左移至最右端,你只 ...

  8. 5.29 省选模拟赛 波波老师 SAM 线段树 单调队列 并查集

    LINK:波波老师 LINK:同bzoj 1396 识别子串 不过前者要求线性做法 后者可以log过.实际上前者也被我一个log给水过了. 其实不算很水 我自认跑的很快罢了. 都是求经过一个位置的最短 ...

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

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

随机推荐

  1. 【Unity Shader学习笔记】Unity基础纹理-渐变纹理

    纹理可以用来存储任何表面属性. 可以通过使用渐变纹理来实现插画风格的渲染效果. 这项技术是由Valve公司提出的.Valve使用它来渲染游戏中具有插画风格的角色. 我们使用半兰伯特模型计算漫反射. 因 ...

  2. python基础学习9

    python基础学习 内容概要 字符编码的简介 字符编码的发展史 字符编码的实际应用 文件操作简介 文件读写模式 文件操作模式 文件操作方法 内容详情 字符编码的简介 # 字符编码主要研究的对象是文本 ...

  3. npm init cabloy背后的故事

    背景 我们知道许多框架会提供一个脚手架工具,我们先下载安装脚手架工具,然后再通过脚手架命令行来创建项目.在npm@6.1.0中引入了npm init <initializer>的语法.简单 ...

  4. ShardingSphere-proxy-5.0.0部署之分表实现(一)

    一.说明 环境准备:JDK8+     mysql 5.x 官网:https://shardingsphere.apache.org/ 下载地址:https://archive.apache.org/ ...

  5. 【转载】k8s入坑之路(2)kubernetes架构详解

    每个微服务通过 Docker 进行发布,随着业务的发展,系统中遍布着各种各样的容器.于是,容器的资源调度,部署运行,扩容缩容就是我们要面临的问题. 基于 Kubernetes 作为容器集群的管理平台被 ...

  6. redis相关知识点

    redis 的相关知识点 启动 启动代码 redis-cli -a 密码 通用命令 expire: 设置有效期 expire name 10 key key * 相关数据类型 String set:添 ...

  7. SQLite数据库损坏及其修复探究

    数据库如何发生损坏   SQLite 数据库具有很强的抗损坏能力.在执行事务时如果发生应用程序崩溃.操作系统崩溃甚至电源故障,那么在下次访问数据库文件时,会自动回滚部分写入的事务.恢复过程是全自动的, ...

  8. Leetcode 1051. 高度检查器

    这题的目的是找出排序后和排序前位置不同的元素的个数 正常通过复制出一个新的数组,然后对比排序后的数组就能做出,但是时间是1ms 然后发现一种基于桶排序来计数的做法 public int heightC ...

  9. SAP Web Dynpro - 教程

    SAP Web Dynpro是一种标准的SAP UI技术,用于使用图形工具和与ABAP工作台集成的开发环境来开发Web应用程序. 图形工具的使用减少了实施工作,并有助于维护ABAP工作台中的组件. 本 ...

  10. 说什么也要脱单——Python WEB开发:用Tornado框架制作简易【表白墙】网站

    先来哔哔两句:(https://jq.qq.com/?_wv=1027&k=QgGWqAVF) 今天我们要用Python做Web开发,做一个简单的[表白墙]网站.众所周知表白墙的功能普遍更多的 ...