Description

Oh those picky N (1 <= N <= 50,000) cows! They are so picky that each one will only be milked over some precise time interval A..B (1 <= A <= B <= 1,000,000), which includes both times A and B. Obviously, FJ must create a reservation system to determine which stall each cow can be assigned for her milking time. Of course, no cow will share such a private moment with other cows. Help FJ by determining: * The minimum number of stalls required in the barn so that each cow can have her private milking period * An assignment of cows to these stalls over time

有N头牛,每头牛有个喝水时间,这段时间它将专用一个Stall 现在给出每头牛的喝水时间段,问至少要多少个Stall才能满足它们的要求

Input

* Line 1: A single integer, N

* Lines 2..N+1: Line i+1 describes cow i's milking interval with two space-separated integers.

Output

* Line 1: The minimum number of stalls the barn must have.

* Lines 2..N+1: Line i+1 describes the stall to which cow i will be assigned for her milking period.

Sample Input

5
1 10
2 4
3 6
5 8
4 7

Sample Output

4

OUTPUT DETAILS:

Here's a graphical schedule for this output:

Time 1 2 3 4 5 6 7 8 9 10
Stall 1 c1>>>>>>>>>>>>>>>>>>>>>>>>>>>
Stall 2 .. c2>>>>>> c4>>>>>>>>> .. ..
Stall 3 .. .. c3>>>>>>>>> .. .. .. ..
Stall 4 .. .. .. c5>>>>>>>>> .. .. ..

Other outputs using the same number of stalls are possible.

===================================华丽丽的分割线============================================

只要写一个支持区间修改和全局最大值查询的东西就好辣~

那不如直接写一个线段数暖手手~~~

这题好像可以直接差分然后就完了吧。。。

时间复杂度O(nlogn),代码如下:

 #include <bits/stdc++.h>
#define Maxn 1000007
using namespace std;
int read()
{
int x=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
struct seg
{
int lx,rx,mx,tag;
};
seg tree[Maxn*];
int n;
void build(int node, int l, int r)
{
tree[node].lx=l,tree[node].rx=r;
tree[node].tag=,tree[node].mx=;
if (l==r) return;
int mid=(l+r)/;
build(node*,l,mid);
build(node*+,mid+,r);
}
void pushdown(int node)
{
if (tree[node].tag==) return;
tree[node*].tag+=tree[node].tag;
tree[node*].mx+=tree[node].tag;
tree[node*+].tag+=tree[node].tag;
tree[node*+].mx+=tree[node].tag;
tree[node].tag=;
}
void update(int node, int l, int r, int del)
{
if (tree[node].rx<l) return;
if (tree[node].lx>r) return;
if (tree[node].lx>=l&&tree[node].rx<=r)
{
tree[node].tag+=del;
tree[node].mx+=del;
return;
}
pushdown(node);
update(node*,l,r,del);
update(node*+,l,r,del);
tree[node].mx=max(tree[node*].mx,tree[node*+].mx);
}
int main()
{
n=read();
build(,,);
for (int i=;i<=n;i++)
{
int x=read(),y=read();
update(,x,y,);
}
printf("%d\n",tree[].mx);
return ;
}

【数据结构】bzoj1651专用牛棚的更多相关文章

  1. BZOJ1651: [Usaco2006 Feb]Stall Reservations 专用牛棚

    1651: [Usaco2006 Feb]Stall Reservations 专用牛棚 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 509  Sol ...

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

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

  3. BZOJ 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚

    题目 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 553   ...

  4. 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚

    1651: [Usaco2006 Feb]Stall Reservations 专用牛棚 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 566  Sol ...

  5. 【BZOJ】1651: [Usaco2006 Feb]Stall Reservations 专用牛棚(线段树/前缀和 + 差分)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1651 很奇妙.. 我们发现,每一时刻的重叠数选最大的就是答案.... orz 那么我们可以线段树维护 ...

  6. bzoj 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚【贪心+堆||差分】

    这个题方法还挺多的,不过洛谷上要输出方案所以用堆最方便 先按起始时间从小到大排序. 我用的是greater重定义优先队列(小根堆).用pair存牛棚用完时间(first)和牛棚编号(second),每 ...

  7. BZOJ 1651 [Usaco2006 Feb]Stall Reservations 专用牛棚:优先队列【线段最大重叠层数】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1651 题意: 给你n个线段[a,b],问你这些线段重叠最多的地方有几层. 题解: 先将线段 ...

  8. usaco silver刷水~其实是回顾一下,补题解

    [BZOJ1606][Usaco2008 Dec]Hay For Sale 裸01背包 ;i<=n;i++) for(int j=m;j>=a[i];j--) f[j]=max(f[j], ...

  9. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

随机推荐

  1. struts2官方 中文教程 系列六:表单验证

    先贴个本帖的地址,以免被爬:struts2教程 官方系列六:表单验证  即 http://www.cnblogs.com/linghaoxinpian/p/6906720.html 下载本章节代码 介 ...

  2. 使用sqoop将mysql中表导入hive中报错

    [hdfs@node1 root]$ sqoop import --connect jdbc:mysql://node2:3306/cm?charset-utf8 --username root -- ...

  3. RTSC和XDCTool的理解

    1. 在使用TI的开发工具CCS中,里面有几个重要的概念,一直不太清晰,RTSC是什么,XDCTool是什么?包是什么?包的版本为啥都是4位的(比如mathlib_c66x_3_0_1_1)?star ...

  4. Android系统自带样式

    android:theme="@android:style/Theme.Dialog" 将一个Activity显示为能话框模式  android:theme="@andr ...

  5. [转][赞]Android开发者必知的开发资源

    英文原文:Bongzimo  翻译: ImportNew-黄小非 随着Android平台市场份额的持续猛增 ,越来越多的开发者开始投入Android应用程序的开发大潮.如果您是一位2013年刚刚入行的 ...

  6. VSCode 前端必备插件

    VSCode 前端必备插件 Debugger for Chrome 让 vscode 映射 chrome 的 debug功能,静态页面都可以用 vscode 来打断点调试 { "versio ...

  7. python 网络篇(计算机网络基础)

                               计算机网络的发展及基础网络概念                    广播 主机之间“一对所有”的通讯模式,网络对其中每一台主机发出的信号都进行无 ...

  8. XmlAutoGo

    一个基于 Selenium 3.14.0的脚本执行工具,支持自动化解决方案.Github https://github.com/freeol/XmlAutoGo Document https://xm ...

  9. windows下git hub的GUI软件配置与使用

    转载自:http://www.cnblogs.com/haore147/p/3618930.html   1. 安装两个软件 1 2 1. git的命令行程序--git for windows:htt ...

  10. .Net 面试总结

    今天去面试了一家公司,做电子商务类的网站的,公司的老板应该比较有能量,可以同时拿下若干项目,技术负责人给提了几个问题: 记不清顺序了 .net 构析函数的作用 泛型的主要作用及应用方面 结构与类的区别 ...