\(10^18\)是要long long的。

\(nlogn\)单调队列上维护\(logn\)线段树。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <cmath>
  6. #define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
  7. #define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
  8. #define Max(a,b) ((a) > (b) ? (a) : (b))
  9. #define Min(a,b) ((a) < (b) ? (a) : (b))
  10. #define Fill(a,b) memset(a, b, sizeof(a))
  11. #define Abs(a) ((a) < 0 ? -(a) : (a))
  12. #define Swap(a,b) a^=b^=a^=b
  13. #define ll long long
  14. #define ON_DEBUG
  15. #ifdef ON_DEBUG
  16. #define D_e_Line printf("\n\n----------\n\n")
  17. #define D_e(x) cout << #x << " = " << x << endl
  18. #define Pause() system("pause")
  19. #define FileOpen() freopen("in.txt","r",stdin);
  20. #else
  21. #define D_e_Line ;
  22. #define D_e(x) ;
  23. #define Pause() ;
  24. #define FileOpen() ;
  25. #endif
  26. struct ios{
  27. template<typename ATP>ios& operator >> (ATP &x){
  28. x = 0; int f = 1; char c;
  29. for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
  30. while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
  31. x*= f;
  32. return *this;
  33. }
  34. }io;
  35. using namespace std;
  36. const int N = 100007;
  37. int n;
  38. #define lson rt << 1, l, mid
  39. #define rson rt << 1 | 1, mid + 1, r
  40. int t[N << 2];
  41. inline void Pushup(int rt){
  42. t[rt] = Max(t[rt << 1], t[rt << 1 | 1]);
  43. }
  44. inline void Updata(int rt, int l, int r, int x, int w){
  45. if(l == r){
  46. t[rt] = w;
  47. return;
  48. }
  49. int mid = (l + r) >> 1;
  50. if(x <= mid)
  51. Updata(lson, x, w);
  52. else
  53. Updata(rson, x, w);
  54. Pushup(rt);
  55. }
  56. inline int Query(int rt, int l, int r, int L, int R){
  57. if(L <= l && r <= R){
  58. return t[rt];
  59. }
  60. int mid = (l + r) >> 1, maxx = 0;
  61. if(L <= mid) maxx = max(maxx, Query(lson, L, R));
  62. if(R > mid) maxx = max(maxx, Query(rson, L, R));
  63. return maxx;
  64. }
  65. long long sum[N];
  66. int main(){
  67. //FileOpen();
  68. long long Val;
  69. io >> n >> Val;
  70. R(i,1,n){
  71. int x, y;
  72. io >> x >> y;
  73. sum[i] = sum[i - 1] + x;
  74. Updata(1, 1, n, i, y);
  75. }
  76. int ans = 2147483647;
  77. int r = 1;
  78. R(l,1,n){
  79. while(r <= n && sum[r] - sum[l - 1] < Val) ++r;
  80. if(r > n) break;
  81. int newAns = Query(1, 1, n, l, r);
  82. ans = Min(ans, newAns);
  83. }
  84. printf("%d", ans);
  85. return 0;
  86. }

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. MUI+html5的plus.webview页面传值在电脑浏览器上不可见

    使用plus.webview.currentWebview() 获得当前窗口的webview对象后,再使用document.write()输出显示webview的某个属性值,而plus.webview ...

  2. 纯CSS如何禁止用户复制网页的内容?

    大家好,我是半夏,一个刚刚开始写文的沙雕程序员.如果喜欢我的文章,可以关注 点赞 加我微信:frontendpicker,一起学习交流前端,成为更优秀的工程师-关注公众号:搞前端的半夏,了解更多前端知 ...

  3. 深入浅出Nginx实战与架构

    本文主要内容如下(让读者朋友们深入浅出地理解Nginx,有代码有示例有图): 1.Nginx是什么? 2.Nginx具有哪些功能? 3.Nginx的应用场景有哪些? 4.Nginx的衍生生态有哪些? ...

  4. 架构师必备:HBase行键设计与应用

    首先要回答一个问题,为何要使用HBase? 随着业务不断发展.数据量不断增大,MySQL数据库存在这些问题: MySQL支持的数据量为TB级,不能一直保留历史数据.而HBase支持的数据量为PB级,适 ...

  5. Redis 中的原子操作(3)-使用Redis实现分布式锁

    Redis 中的分布式锁如何使用 分布式锁的使用场景 使用 Redis 来实现分布式锁 使用 set key value px milliseconds nx 实现 SETNX+Lua 实现 使用 R ...

  6. 想知道Vue3与Vue2的区别?五千字教程助你快速上手Vue3!

    从Vue3发布以来,我就一直对其非常感兴趣,就一直想着将其投入公司的生产中,但是开始考虑到很多不确定性就暂时对一些很小的功能进行一些尝试:慢慢的发现组合式Api的形式非常适合开发(个人感觉),尤其是V ...

  7. [安洵杯 2019]easy_web-1

    1.首先打开题目如下: 2.观察访问的地址信息,发现img信息应该是加密字符串,进行尝试解密,最终得到img名称:555.png,如下: 3.获得文件名称之后,应该想到此处会存在文件包含漏洞,因为传输 ...

  8. SAP BPC 清除CUBE 中的数据

    原理:先根据模型和查询条件取出数据,然后把金额设置为0,再写回CUBE. 1.获取数据并清空金额 *&--------------------------------------------- ...

  9. js 生成的html class属性失效问题

    var html = '<fieldset class="struct-info" id="SlopeZY"><legend>变坡点(Z ...

  10. 关于android里activity之间利用button组件使用intent跳转页面

    在需要跳转的activity 中 添加 Button button = findViewById(R.id.login);button.setOnClickListener(new View.OnCl ...