【题解】

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

 #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. BSGS算法及拓展

    https://www.zybuluo.com/ysner/note/1299836 定义 一种用来求解高次同余方程的算法. 一般问题形式:求使得\(y^x\equiv z(mod\ p)\)的最小非 ...

  2. 使用Oracle Sql Developer将SQL SERVER 2008数据库移植到Oracle 11g

    ORACLE官方提供的Sql Developer自带的Oracle Migration Workbench. 什么是Oracle SQL Developer?在官方页面上,是这样介绍它的: Oracl ...

  3. jQuery EasyUI,LinkButton(按钮)组件

    转自:https://www.cnblogs.com/adc8868/p/6639570.html jQuery EasyUI,LinkButton(按钮)组件 学习要点: 1.加载方式 2.属性列表 ...

  4. 29. ExtJs - Struts2 整合(1) - 登录页面

    转自:https://yarafa.iteye.com/blog/729197 初学 ExtJS,在此记录下学习过程中的点点滴滴,以备不时只需,也希望能给跟我一样的菜鸟一些帮助,老鸟请忽略.如有不当之 ...

  5. Nginx配置try_files实践二

    本文内容承接<Nginx配置try_files实践一> 1. 环境: OS:Ubuntu 15.10 nginx:nginx/1.9.3 (Ubuntu) 假设有三台虚拟机db1(IP:1 ...

  6. bzoj 1677: [Usaco2005 Jan]Sumsets 求和【dp】

    设f[i]为i的方案数,f[1]=1,考虑转移,如果是奇数,那么就是f[i]=f[i-1]因为这1一定要加:否则f[i]=f[i-1]+f[i>>1],就是上一位+1或者i/2位所有因子乘 ...

  7. 微信扫码下载APK遮罩提示示例

    由于微信的限制,应用文件在内置浏览器中下载全部被屏蔽掉,造成很多人用微信扫描二维码下载时,界面显示一片空白,容易误导以为在下载呢.按照当前主流习惯,做一个提示用户在浏览器中打开下载的遮罩.网上很多现成 ...

  8. Invalid default value for 'create_date' timestamp field

    创建表的语句中有这么一句 `create_date` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00', 1 之后就报了这个错误. That is be ...

  9. 用Movie显示gif(1)SimpleGif

    代码如下: import android.content.Context; import android.graphics.Canvas; import android.graphics.Movie; ...

  10. Android 性能优化(16)线程优化:Creating a Manager for Multiple Threads 如何创建一个线程池管理类

    Creating a Manager for Multiple Threads 1.You should also read Processes and Threads The previous le ...