【题解】

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

 #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. Oracle强杀进程

      1.找到sid,serial#: SELECT /*+ rule */ s.username, l.type, decode(l.type,'TM','TABLE LOCK',           ...

  2. Eclipse中执行sql脚本文件

    转自:https://blog.csdn.net/weixin_37778823/article/details/79614281 在Eclipse中导入或新建sql脚本文件(.sql文件),选择指定 ...

  3. apache相关补充

    apache相关补充 sendfile机制 1)不用sendfile的传统网络传输过程: read(file, tmp_buf, len) write(socket, tmp_buf, len) 2) ...

  4. HTML5牛刀小试

    第一周的HTML5苦逼之路,就这么简单,充实,忙碌的开始了,丝毫不敢有一丢丢懈怠,压力是有的,但更多的是对自己的信心,更是对自己的踏上苦逼之路的意志的肯定. 简单回顾了下这周所学内容.从认识HTML基 ...

  5. 公司5:JrVue表格

    组件名称:jr-dynamic-query-table 组件布局 table组件名称:  jr-dynamic-query-table 分页组件名称: el-pagination <div re ...

  6. xposed源码编译与集成

    xposed installer3.0版本之后,传统的xposed框架的使用方法是从官网上下载xposed installer.apk以及xposed-arm-sdk22.zip包.然后具体的使用方法 ...

  7. redis的两种备份方式

    Redis提供了两种持久化选项,分别是RDB和AOF. 默认情况下60秒刷新到disk一次[save 60 10000 当有1w条keys数据被改变时],Redis的数据集保存在叫dump.rdb一个 ...

  8. [SDOI2013]泉

    题目描述 作为光荣的济南泉历史研究小组中的一员,铭铭收集了历史上x个不同年份时不同泉区的水流指数,这个指数是一个小于. 2^30的非负整数.第i个年份时六个泉区的泉水流量指数分别为 A(i,l),A( ...

  9. hdu6195 cable cable cable

    cable cable cable Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  10. Windows平台下Oracle监听服务启动过程中日志输出

    Windows平台下Oracle监听服务启动过程中日志输出记录. 日志目录:D:\app\Administrator\diag\tnslsnr\WIN-RU03CB21QGA\listener\tra ...