【题解】

  贪心。 把区间按照右端点从小到大排序,右端点相同的按照长度从小到大排序,然后按顺序考虑,能放就放下去。 维护能不能放下去用线段树即可。

 #include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
#define rg register
#define N 100010
#define ls (u<<1)
#define rs (u<<1|1)
using namespace std;
int n,m,ans,mn[N<<],del[N<<];
struct seg{
int l,r;
}a[N];
inline int read(){
int k=,f=; char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(''<=c&&c<='')k=k*+c-'',c=getchar();
return k*f;
}
void build(int u,int l,int r){
if(l<r){
int mid=(l+r)>>;
build(ls,l,mid),build(rs,mid+,r),mn[u]=min(mn[ls],mn[rs]);
}
else mn[u]=read();
}
inline void pushdown(int u){
mn[ls]+=del[u]; del[ls]+=del[u];
mn[rs]+=del[u]; del[rs]+=del[u];
del[u]=;
}
void update(int u,int l,int r,int ul,int ur){
if(ul<=l&&r<=ur){
mn[u]--; del[u]-=;
return;
}
int mid=(l+r)>>; pushdown(u);
if(ul<=mid) update(ls,l,mid,ul,ur);
if(ur>mid) update(rs,mid+,r,ul,ur);
mn[u]=min(mn[ls],mn[rs]);
}
int query(int u,int l,int r,int ul,int ur){
if(ul<=l&&r<=ur) return mn[u];
int mid=(l+r)>>,ret=2e9; pushdown(u);
if(ul<=mid) ret=min(ret,query(ls,l,mid,ul,ur));
if(ur>mid) ret=min(ret,query(rs,mid+,r,ul,ur));
return ret;
}
inline bool cmp(seg a,seg b){
if(a.r==b.r) return a.l>b.l;
return a.r<b.r;
}
int main(){
n=read(); m=read(); build(,,n);
for(rg int i=;i<=m;i++) a[i].l=read(),a[i].r=read();
sort(a+,a++m,cmp);
for(rg int i=;i<=m;i++){
int tmp=query(,,n,a[i].l,a[i].r);
if(tmp>){
ans++;
update(,,n,a[i].l,a[i].r);
}
}
printf("%d\n",ans);
return ;
}

洛谷 1937 [USACO10MAR]仓配置Barn Allocation的更多相关文章

  1. 洛谷P1937 [USACO10MAR]仓配置Barn Allocation

    题目描述 Farmer John recently opened up a new barn and is now accepting stall allocation requests from t ...

  2. AC日记——[USACO10MAR]仓配置Barn Allocation 洛谷 P1937

    [USACO10MAR]仓配置Barn Allocation 思路: 贪心+线段树维护: 代码: #include <bits/stdc++.h> using namespace std; ...

  3. LUOGU P1937 [USACO10MAR]仓配置Barn Allocation

    传送门 解题思路 扫了一眼觉得是贪心+线段树,结果贪心的时候刚开始按区间长度排的序..这还有82分,后来叉了自己,换成按右端点排序过了. 代码 #include<iostream> #in ...

  4. 洛谷 P2986 [USACO10MAR]伟大的奶牛聚集Great Cow Gat…(树规)

    题目描述 Bessie is planning the annual Great Cow Gathering for cows all across the country and, of cours ...

  5. 洛谷 P2986 [USACO10MAR]Great Cow Gat…(树形dp+容斥原理)

    P2986 [USACO10MAR]伟大的奶牛聚集Great Cow Gat… 题目描述 Bessie is planning the annual Great Cow Gathering for c ...

  6. 洛谷 P2986 [USACO10MAR]伟大的奶牛聚集(树形动规)

    题目描述 Bessie is planning the annual Great Cow Gathering for cows all across the country and, of cours ...

  7. 洛谷P3066 [USACO12DEC]逃跑的Barn (线段树合并)

    题目描述It's milking time at Farmer John's farm, but the cows have all run away! Farmer John needs to ro ...

  8. 洛谷P3066 [USACO12DEC] 逃跑的Barn [左偏树]

    题目传送门 逃跑的Barn 题目描述 It's milking time at Farmer John's farm, but the cows have all run away! Farmer J ...

  9. Java实现 洛谷 P6183 [USACO10MAR]The Rock Game S(DFS)

    P6183 [USACO10MAR]The Rock Game S 输入输出样例 输入 3 输出 OOO OXO OXX OOX XOX XXX XXO XOO OOO PS: 因为每一位只有两种可能 ...

随机推荐

  1. 【转】整套完整安全的API接口解决方案

    原文地址:http://www.cnblogs.com/hubro/p/6248353.html 在各种手机APP泛滥的现在,背后都有同样泛滥的API接口在支撑,其中鱼龙混杂,直接裸奔的WEB API ...

  2. 14. extjs中treepanel属性和方法

    转自:http://www.cnblogs.com/connortang/p/4414907.html 1.Ext.tree.TreePanel 主要配置项: root:树的根节点. rootVisi ...

  3. eclipse maven创建web项目

    记录地址 jdk设置及文件包miss 实例下载地址 创建SSM整合项目 一.使用Eclipse中的maven插件创建web项目 1: 2: 3: 4: 5:maven web项目创建成功.(去掉ind ...

  4. java笔记线程方式1等待终止

    public final void join():等待该线程终止 public class ThreadJoinDemo { public static void main(String[] args ...

  5. uml图六种箭头的含义(转载)

    在看一些技术博客的时候,经常会见到博客里画上很多uml图.因为经常会被这几种表达关系的箭头搞混,这里我就把常见的6种箭头表达的含义理一下. 泛化 概念:泛化是一种一般与特殊.一般与具体之间关系的描述, ...

  6. [Swift通天遁地]一、超级工具-(10)使用地图视图MKMapView的相机功能实现创建三维地图

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  7. java io 文件下载

    /** * 文件下载 * @param response * @param downloadPath * @param docName */ public void downLoadFile( Htt ...

  8. ListView(4)取消GridView/ListView item被点击时的效果

    方法一,在代码中设置 gridView.setSelector(new ColorDrawable(Color.TRANSPARENT)); listView.setSelector(new Colo ...

  9. CircuitBreaker design pattern---reference

    It's common for software systems to make remote calls to software running in different processes, pr ...

  10. .net 反射初体验

    一.获取对象中的所有属性 Type是.net定义的一个反射的类.通过反射获取到对象的所有属性,然后根据属性获取对象对应属性所对应的值. 使用PropertyInfo,请引用命名空间using Syst ...