题目描述 Farmer John has been having trouble making his plants grow, and needs your help to water them properly. You are given the locations of N raindrops (1 <= N <= 100,000) in the 2D plane, where y represents vertical height of the drop, and x repres…
[USACO12MAR]花盆 二分 单调队列 存在一个长度为\(x\)的区间\([l,r]\),使得区间中最大值与最小值差至少为\(w\),求这个最小的\(x\) \(n\le 100000\),\(w\le 1000000\) 显然区间长度\(x\)越大,最值之差越大,满足单调性,上二分答案,问题转化为是否存在长度为\(mid\)的区间中最值之差至少为\(w\),而这个问题可以用单调队列(滑动窗口)\(O(n)\)解决. 单调队列存的下标,首先判断队首是否合法(窗口大小),然后按照"比你强还比…
P2698 [USACO12MAR]花盆Flowerpot 一看标签........十分后悔 标签告诉你单调队列+二分了............ 每次二分花盆长度,蓝后开2个单调队列维护最大最小值 蓝后就是code了 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; inline int Max(int a,int b)…
描述 Farmer John has been having trouble making his plants grow, and needs your help to water them properly. You are given the locations of N raindrops (1 <= N <= 100,000) in the 2D plane, where y represents vertical height of the drop, and x represen…
https://www.luogu.org/problemnew/show/P2698 警示 用数组写双端队列的话,记得le = 1, ri = 0:le<=ri表示队列非空 题意 求一个最小的区间长度,使得区间中的最大值和最小值的差>=D. 思路 一开始二分加线段树强行做,多了一个log.用ST表可能会优秀.做到nlogn.但是如果用单调队列的话,除去排序,就可以做到O(n)具体来说,对于一个L,合法的最小的右区间若为R,那么L+1的最小合法右区间一定>=R. #include <…
题目链接 Solution 转化一下,就是个单调队列. 可以发现就是一段区间 \([L,R]\) 使得其高度的极差不小于 \(d\) ,同时满足 \(R-L\) 最小. 然后可以考虑二分然后再 \(O(n)\) 判断, 时间复杂度 \(O(nlogn)\) . Code #include<bits/stdc++.h> #define ll long long #define inf 0x3f3f3f3f using namespace std; const int maxn=1000008;…
P2698 [USACO12MAR]花盆Flowerpot 题目描述 Farmer John has been having trouble making his plants grow, and needs your help to water them properly. You are given the locations of N raindrops (1 <= N <= 100,000) in the 2D plane, where y represents vertical he…
Link: P2698 传送门 Solution: 对于可行区间$[L,R]$,随着$L$的递增$R$不会递减 因此可以使用尺取法来解决此题:不断向右移动左右指针,复杂度保持线性 同时为了维护区间内的最值,要设立两个单调队列来维护最大/最小值 每次当$L$增加时,要从队列头部删去小于$L$的节点(如果后面还有不用管,以后自然会删去) Code: #include <bits/stdc++.h> using namespace std; typedef pair<int,int> P…
E.Easy Climb Somewhere in the neighborhood we have a very nice mountain that gives a splendid view over the surrounding area. There is one problem though: climbing this mountain is very difficult, because of rather large height differences. To make m…
大sz的游戏 Time Limit: 50 Sec  Memory Limit: 357 MBSubmit: 536  Solved: 143[Submit][Status][Discuss] Description 大sz最近在玩一个由星球大战改编的游戏.话说绝地武士当前共控制了N个星球.但是,西斯正在暗处悄悄地准备他们的复仇计划.绝地评议会也感觉到了这件事.于是,准备加派绝地武士到各星球防止西斯的突袭.一个星球受到攻击以后,会尽快通知到总基地.需要的时间越长的星球就需要越多绝地武士来防御.为…