题面:P4269 [USACO18FEB]Snow Boots G

题解:

把所有砖和靴子排序,然后依次处理每一双靴子,把深度小于等于它的砖块都扔线段树里,问题就转化成了求线段树已有的砖块中最大的砖块间距是否小于当前靴子间距。

代码:

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define max(a,b) ((a)>(b)?(a):(b))
using namespace std;
const int maxn=(1e5)+,maxb=(1e5)+;
int N,B,f1;
bool ans[maxb];
struct P{
int x,id,d;
}F[maxn],S[maxb];
struct Tree{
int l,r,h_,t_,mx;
}t[maxn<<];
inline bool cmp(const P&a,const P&b){return(a.x<b.x);}
inline void Pushup(int x){
int ls=x<<,rs=x<<|;
if(t[ls].r-t[ls].l+==t[ls].mx)t[x].h_=t[ls].mx+t[rs].h_;else t[x].h_=t[ls].h_;
if(t[rs].r-t[rs].l+==t[rs].mx)t[x].t_=t[rs].mx+t[ls].t_;else t[x].t_=t[rs].t_;
t[x].mx=max(t[ls].mx,t[rs].mx);
t[x].mx=max(t[x].mx,t[ls].t_+t[rs].h_);
return;
}
inline void Build(int x,int l,int r){
t[x].l=l;t[x].r=r;
if(l==r){
t[x].h_=t[x].t_=t[x].mx=;
return;
}
int mid=(l+r)>>,ls=x<<,rs=x<<|;
Build(ls,l,mid);Build(rs,mid+,r);
Pushup(x);
return;
}
inline void Update(int x,int q){
int l=t[x].l,r=t[x].r;
if(l==r&&l==q){
t[x].h_=t[x].t_=t[x].mx=;
return;
}
int mid=(l+r)>>,ls=x<<,rs=x<<|;
if(q<=mid)Update(ls,q);
else Update(rs,q);
Pushup(x);
return;
}
int main(){
scanf("%d%d",&N,&B);
for(int i=;i<=N;i++){
scanf("%d",&F[i].x);
F[i].id=i;
}
for(int i=;i<=B;i++){
scanf("%d%d",&S[i].x,&S[i].d);
S[i].id=i;
}
sort(F+,F+N+,cmp);
sort(S+,S+B+,cmp);
Build(,,N);
f1=;//F是地砖,S是靴子 ;f1是地砖,f2是靴子
for(int f2=;f2<=B;f2++){//依次处理每一双靴子
while(f1<N&&F[f1+].x<=S[f2].x){
f1++;
Update(,F[f1].id);
}
if(t[].mx<S[f2].d)ans[S[f2].id]=;
}
for(int i=;i<=B;i++)printf("%d\n",ans[i]);
return ;
}

By:AlenaNuna

线段树||BZOJ5194: [Usaco2018 Feb]Snow Boots||Luogu P4269 [USACO18FEB]Snow Boots G的更多相关文章

  1. 线段树||BZOJ1593: [Usaco2008 Feb]Hotel 旅馆||Luogu P2894 [USACO08FEB]酒店Hotel

    题面:P2894 [USACO08FEB]酒店Hotel 题解:和基础的线段树操作差别不是很大,就是在传统的线段树基础上多维护一段区间最长的合法前驱(h_),最长合法后驱(t_),一段中最长的合法区间 ...

  2. BZOJ5194: [Usaco2018 Feb]Snow Boots(排序&set)(可线段树优化)

    5194: [Usaco2018 Feb]Snow Boots Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 102  Solved: 79[Subm ...

  3. bzoj5194: [Usaco2018 Feb]Snow Boots

    还真是.. 就是 一个被不点名批评的垃圾骗分暴力选手被普及难度的省选信心(??)模拟赛艹爆的题解 的t3嘛... #include<cstdio> #include<iostream ...

  4. 线段树初步——转载自ljc20020730

    线段树初步   线段树模板1:https://www.luogu.org/problem/show?pid=3372 线段树模板2:https://www.luogu.org/problem/show ...

  5. 2021.12.08 P1848 [USACO12OPEN]Bookshelf G(线段树优化DP)

    2021.12.08 P1848 [USACO12OPEN]Bookshelf G(线段树优化DP) https://www.luogu.com.cn/problem/P1848 题意: 当农夫约翰闲 ...

  6. 【bzoj5123】[Lydsy12月赛]线段树的匹配 树形dp+记忆化搜索

    题目描述 求一棵 $[1,n]$ 的线段树的最大匹配数目与方案数. $n\le 10^{18}$ 题解 树形dp+记忆化搜索 设 $f[l][r]$ 表示根节点为 $[l,r]$ 的线段树,匹配选择根 ...

  7. HDU 5266 pog loves szh III 线段树,lca

    Pog and Szh are playing games. Firstly Pog draw a tree on the paper. Here we define 1 as the root of ...

  8. Bzoj[Usaco2018 Feb]5194 Snow Boots(线段树)

    Description 到冬天了,这意味着下雪了!从农舍到牛棚的路上有N块地砖,方便起见编号为1…N,第i块地砖上积了fi英尺的雪 .在Farmer John的农舍的地窖中,总共有B双靴子,编号为1… ...

  9. BZOJ 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚( 线段树 )

    线段树.. -------------------------------------------------------------------------------------- #includ ...

随机推荐

  1. !HDU 1574 RP-dp-(重点在状态确定)

    题意:有n件事.每件事若发生有两种情况.添加RP为a,可是收益会降低c:降低R为a,收益会添加c. 每件事可以发生的前提是小于等于或者大于等于门限值b.求最大收益. 分析:这题我没找到状态,所以就不会 ...

  2. LeetCode Permutations问题详解

    题目一 permutations 题目描述 Given a collection of numbers, return all possible permutations. For example,[ ...

  3. 启动Jupyter Notebook

    按照图所示,在命令下输入ipython notebook 即可启动Jupyter. 启动后的效果:

  4. openjudge noi 鸡尾酒疗法

    题目链接:http://noi.openjudge.cn/ch0105/18/ 总时间限制: 1000ms 内存限制: 65536kB 描述 鸡尾酒疗法,原指“高效抗逆转录病毒治疗”(HAART),由 ...

  5. jquery ajax IE

    在ie上会出现,get/post 只调用一次的现象 解决方法: cache:false http://stackoverflow.com/questions/8841425/how-to-set-ca ...

  6. 9.8 翻译系列:数据注解特性之--Required 【EF 6 Code-First系列】

    原文链接:https://www.entityframeworktutorial.net/code-first/required-attribute-dataannotations-in-code-f ...

  7. Python中的zip()与*zip()函数详解

    前言 实验环境: Python 3.6: 示例代码地址:下载示例: 本文中元素是指列表.元组.字典等集合类数据类型中的下一级项目(可能是单个元素或嵌套列表). zip(*iterables)函数详解 ...

  8. RNN,LSTM,GRU简单图解:

    一篇经典的讲解RNN的,大部分网络图都来源于此:http://colah.github.io/posts/2015-08-Understanding-LSTMs/ 每一层每一时刻的输入输出:https ...

  9. FROM USE CASES TO TEST CASES

    FROM USE CASES TO TEST CASES -Test note of “Essential Software Test Design” 2015-08-31 Content: 12.1 ...

  10. [转]Ubuntu 16.04安装有道词典

    原文:https://www.cnblogs.com/scplee/archive/2016/05/13/5489024.html 以前用Ubuntu 14.04 的时候,直接下载有道词典官方deb安 ...