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. CSS3实现加载数据动画1

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. cadence17.2的OrCAD启动找不到license的问题

    1. cadence17.2的OrCAD每次启动都说找不到license 2. 提示是找不到licence,看下系统变量,licence的路径是在的 3. 估计是读取licence的路径的服务未开启, ...

  3. 掘金 Android 文章精选合集

    掘金 Android 文章精选合集 掘金官方 关注 2017.07.10 16:42* 字数 175276 阅读 50053评论 13喜欢 669 用两张图告诉你,为什么你的 App 会卡顿? - A ...

  4. 【数据库】 SQL 通配符

    [数据库] SQL 通配符 1. % : 替代一个或多个字符 2. _ : 仅替代一个字符 3. [] : 字符列中的任何单一字符 4. [^charlist] 或者 [!charlist]  : 不 ...

  5. python终极篇 --- django---班级管理系统

    周末没事自己写了个班级管理系统,虽然简单,但也算个前期学习的总结吧 from django.db import models # Create your models here. class Banj ...

  6. python 基础篇03

    本节主要内容:1. python基本数据类型回顾2. int----数字类型3. bool---布尔类型4. str--- 字符串类型一.python基本数据类型1. int ==> 整数. 主 ...

  7. Datenode无法启动

    执行start-dfs.sh后,或者执行datenode没有启动.很大一部分原因是因为在第一次格式化dfs后,启动并使用了hadoop,后来又重新执行了格式化命令 这时主节点namenode的clus ...

  8. BZOJ 2333 SCOI2011 棘手的操作 并查集+可并堆

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2333 ..题意概述就不写了,各位老爷如果是看着玩的可以去搜一下,如果是做题找来的也知道题干 ...

  9. PAT 1055 集体照

    https://pintia.cn/problem-sets/994805260223102976/problems/994805272021680128 拍集体照时队形很重要,这里对给定的 N 个人 ...

  10. 【SSH】——hql的使用方式及实现原理

    [含义] hql,即Hibernate Query  Language.它与我们熟知的sql很类似,它最大的特点就是对查询进行了面向对象的封装,下面会在具体例子中说明. sql查询的是数据库中的表或字 ...