BZOJ 5194--[Usaco2018 Feb]Snow Boots(STL)
5194: [Usaco2018 Feb]Snow Boots
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 81 Solved: 61
[Submit][Status][Discuss]
Description
Input
第一行包含两个空格分隔的整数N和B(1≤N,B≤10^5)。
Output
输出包含N行
Sample Input
0 3 8 5 6 9 0 0
0 5
0 6
6 2
8 1
10 1
5 3
150 7
Sample Output
1
1
0
1
1
1
题目链接:
http://www.lydsy.com/JudgeOnline/problem.php?id=5194
Solution
这种题感觉已经是套路了。。。
反正就是两种思路。。。
1.只走小于D的雪堆需要走的最长的一步。。
2.最长的一步为不超过S的需要走的最大的雪堆。。
这里只写了第1种的。。。第2种应该也能写吧。。
先将所有雪堆从小到大排序,鞋子也要排序。。
对于某一种鞋子的di,求一下需要多大的si。。。就是求一下能走的雪堆的最大间隔。。
每次放入一个新的雪堆只会改变几个间隔大小。。
所以只需要用set维护一下集合内的前驱和后驱,然后用两个优先队列维护一下带删除的集合内最大值。。
然后就做完了。。。
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define pa pair<LL,LL>
#define LL long long
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
inline void Out(int a){
if(a>9) Out(a/10);
putchar(a%10+'0');
}
const LL inf=1e9+10;
const LL mod=1e9+7;
const int N=1e5+50;
int n,m,cnt=1; struct date{
int v,id;
}f[N];
bool cmpd(date A,date B){
return A.v<B.v;
}
struct xie{
int s,d,id;
}a[N];
bool cmpx(xie A,xie B){
return A.s<B.s;
}
set<int> S;
priority_queue<int> P,Q;
void del(int x){
Q.push(x);
while(Q.empty()==0&&P.empty()==0&&Q.top()==P.top()){
P.pop();Q.pop();
}
}
void add(int x){
P.push(x);
}
int ans[N];
int main(){
n=read();m=read();
if(n==1||n==2){
for(int i=1;i<=m;++i){
putchar('1');puts("");
}
return 0;
}
f[1].v=read();
for(int i=2;i<n;++i){
f[i].v=read();f[i].id=i;
}
f[n].v=read();
f[1]=f[n-1];
n=n-2;
for(int i=1;i<=m;++i){
a[i].s=read();a[i].d=read();a[i].id=i;
}
sort(f+1,f+1+n,cmpd);
sort(a+1,a+1+m,cmpx);
P.push(n+1);
set<int>::iterator L,R;
int l,r;
S.insert(1);S.insert(n+2);
for(int i=1,j=1;j<=m;++j){
while(i<=n&&f[i].v<=a[j].s){
R=S.lower_bound(f[i].id);
L=R;--L;
l=*L;r=*R;
del(r-l);
add(f[i].id-l);
add(r-f[i].id);
S.insert(f[i].id);
++i;
}
if(P.top()<=a[j].d) ans[a[j].id]=1;
else ans[a[j].id]=0;
}
for(int i=1;i<=m;++i) printf("%d\n",ans[i]);
return 0;
}
This passage is made by Iscream-2001.
BZOJ 5194--[Usaco2018 Feb]Snow Boots(STL)的更多相关文章
- BZOJ5194: [Usaco2018 Feb]Snow Boots(排序&set)(可线段树优化)
5194: [Usaco2018 Feb]Snow Boots Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 102 Solved: 79[Subm ...
- 线段树||BZOJ5194: [Usaco2018 Feb]Snow Boots||Luogu P4269 [USACO18FEB]Snow Boots G
题面:P4269 [USACO18FEB]Snow Boots G 题解: 把所有砖和靴子排序,然后依次处理每一双靴子,把深度小于等于它的砖块都扔线段树里,问题就转化成了求线段树已有的砖块中最大的砖块 ...
- [Usaco2018 Feb]Snow Boots
Description 到冬天了,这意味着下雪了!从农舍到牛棚的路上有N块地砖,方便起见编号为1-N,第i块地砖上积了fi英尺的雪.在Farmer John的农舍的地窖中,总共有B双靴子,编号为1-B ...
- bzoj5194: [Usaco2018 Feb]Snow Boots
还真是.. 就是 一个被不点名批评的垃圾骗分暴力选手被普及难度的省选信心(??)模拟赛艹爆的题解 的t3嘛... #include<cstdio> #include<iostream ...
- bzoj 5195: [Usaco2018 Feb]Directory Traversal【树形dp】
注意到目录是一颗树结构,然后就简单了,预以1为根的处理出dis[u]为以这个点为根,到子树内的目录总长,si为子树内叶子数 第二遍dfs换根即可 #include<iostream> #i ...
- BZOJ5196: [Usaco2018 Feb]Taming the Herd(DP暴力)
5196: [Usaco2018 Feb]Taming the Herd Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 78 Solved: 71[ ...
- [bzoj 1782] [Usaco2010 Feb]slowdown慢慢游
[bzoj 1782] [Usaco2010 Feb]slowdown慢慢游 Description 每天Farmer John的N头奶牛(1 <= N <= 100000,编号1-N)从 ...
- 2019 GDUT Rating Contest II : Problem G. Snow Boots
题面: G. Snow Boots Input file: standard input Output file: standard output Time limit: 1 second Memory ...
- Bzoj[Usaco2018 Feb]5194 Snow Boots(线段树)
Description 到冬天了,这意味着下雪了!从农舍到牛棚的路上有N块地砖,方便起见编号为1…N,第i块地砖上积了fi英尺的雪 .在Farmer John的农舍的地窖中,总共有B双靴子,编号为1… ...
随机推荐
- 异常处理(异常解析器) 和 对于Properties类型的属性的配置
在程序运行中,有可能因为用户的不当操作,发生异常.. 在springmvc中可以根据不同的异常配置不同的处理方式 1.例如出现 这个类型异常 org.springframework.web.multi ...
- html-day04
html-day04 1.html属性的弊端 1.完成相同的功能需要不同的属性支持 2.可维护性不高2.CSS 1.什么是CSS Cascading Style Sheet 层叠样式表.级联样式表.样 ...
- String拼接
1. String[] members=ArrayDATA_IDS; String usernames = ""; for(String id :members) { userna ...
- vue中使用promise.all发送多个请求
1.创建两个promise,在promise中使用axios 2.调用Promise.all([p1,p2]).then(res=>{}).catch(err=>{})方法 代码如下: & ...
- 下载编译安装Apache HTTP Server 2.4.23以及配置HTTP/HTTPS反向代理
http://blog.csdn.net/gangchengzhong/article/details/52910225 [注意,在编译make时出现的错误并不是文章中说的openssl的版本问题,而 ...
- IntellJ IDEA 2017 激活编译器配置,读取多个配置文件
1.设置编译器,找到1,点击2 2.输入设置命令:--spring.profiles.active=test,如果是多个文件输入--spring.profiles.active=test,dev 3. ...
- poj 2240 Arbitrage(最短路问题)
Description Arbitrage is the use of discrepancies in currency exchange rates to transform one unit o ...
- Ueditor Word图片转存交互
三.Word图片转存交互 1.图片转存原理 所谓word图片转存,是指UEditor为了解决用户从word中复制了一篇图文混排的文章粘贴到编辑器之后,word文章中的图片数据无法显示在编辑器中,也无法 ...
- HTML上传文件支持大文件上传,下载
上传 1.修改配置文件web.config,在<system.webServer>下面加入 <security> <requestFiltering > <r ...
- 记录:CSS特殊性——权值规则
浏览器是根据权值来判断使用哪种css样式的,权值高的就使用哪种css样式. 下面是权值的规则: 标签的权值为1,类选择符的权值为10,ID选择符的权值最高为100.例如下面的代码: p{color:r ...