【题意概述】

  给出一个[0,1,000,000,000]的整数数轴,刚开始每个位置都为0,有n个区间加操作,最后询问数轴上最大的数是多少。

【题解】

  我写的是离散化后线段树维护区间最值。

  其实貌似不用线段树QAQ...

#include<cstdio>
#include<algorithm>
#define N 400010
#define rg register
#define ls (u<<1)
#define rs (u<<1|1)
#define mid ((a[u].l+a[u].r)>>1)
using namespace std;
int n,ans,l[N],r[N],b[N];
struct tree{
int l,r,del,mx;
}a[N];
inline int read(){
int f=1,k=0; char c=getchar();
while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
while('0'<=c&&c<='9')k=k*10+c-'0',c=getchar();
return k*f;
}
inline int max(int a,int b){
return a>b?a:b;
}
inline void pushup(int u){
a[u].mx=max(a[ls].mx,a[rs].mx);
}
inline void pushdown(int u){
if(!a[u].del) return; int D=a[u].del; a[u].del=0;
a[ls].del+=D; a[ls].mx+=D;
a[rs].del+=D; a[rs].mx+=D;
}
void build(int u,int l,int r){
a[u].l=l; a[u].r=r; a[u].mx=0;
if(l<r) build(ls,l,mid),build(rs,mid+1,r);
}
void add(int u,int l,int r,int d){
if(l<=a[u].l&&a[u].r<=r){
a[u].del+=d; a[u].mx+=d; return;
}
pushdown(u);
if(l<=mid) add(ls,l,r,d);
if(r>mid) add(rs,l,r,d);
pushup(u);
}
int query(int u,int l,int r){
if(l<=a[u].l&&a[u].r<=r) return a[u].mx;
pushdown(u); int ret=0;
if(l<=mid) ret=query(ls,l,r);
if(r>mid) ret=max(ret,query(rs,l,r));
return ret;
}
int main(){
n=read();
for(rg int i=1;i<=n;i++){
l[i]=b[i]=read(); r[i]=b[i+n]=read();
}
sort(b+1,b+1+(n<<1)); int n2=unique(b+1,b+1+(n<<1))-b-1;
for(rg int i=1;i<=n;i++) l[i]=lower_bound(b+1,b+1+n2,l[i])-b;
for(rg int i=1;i<=n;i++) r[i]=lower_bound(b+1,b+1+n2,r[i])-b;
// for(rg int i=1;i<=n;i++){
// printf("%d %d\n",l[i],r[i]);
// }
// printf("n2=%d\n",n2);
ans=0; build(1,1,n2);
for(rg int i=1;i<=n;i++){
add(1,l[i],r[i],1);
}
for(rg int i=1;i<=n2;i++){
ans=max(ans,query(1,i,i));
//printf("%d\n",query(1,i,i));
}
printf("%d\n",ans);
return 0;
}

  

BZOJ 2501 [usaco2010 Oct]Soda Machine的更多相关文章

  1. BZOJ 2501: [usaco2010 Oct]Soda Machine 离散+差分

    [usaco2010 Oct]Soda Machine Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 266  Solved: 182[Submit][ ...

  2. [usaco2010 Oct]Soda Machine

    题目描述 有N个人要去膜拜JZ,他们不知道JZ会出现在哪里,因此每个人有一个活动范围,只要JZ出现在这个范围内就能被膜拜, 伟大的JZ当然希望膜拜他的人越多越好,但是JZ不能分身,因此只能选择一个位置 ...

  3. BZOJ2501: [usaco2010 Oct]Soda Machine

    n<=50000个区间,求哪个点被覆盖区间数量最多,输出这个数量. 差分模板..然而数组忘开两倍.. #include<stdio.h> #include<string.h&g ...

  4. [bzoj 1782] [Usaco2010 Feb]slowdown慢慢游

    [bzoj 1782] [Usaco2010 Feb]slowdown慢慢游 Description 每天Farmer John的N头奶牛(1 <= N <= 100000,编号1-N)从 ...

  5. BZOJ 2501 Soda Machine

    BIT+离散化. #include<iostream> #include<cstdio> #include<cstring> #include<algorit ...

  6. BZOJ 1827: [Usaco2010 Mar]gather 奶牛大集会 树形DP

    [Usaco2010 Mar]gather 奶牛大集会 Bessie正在计划一年一度的奶牛大集会,来自全国各地的奶牛将来参加这一次集会.当然,她会选择最方便的地点来举办这次集会.每个奶牛居住在 N(1 ...

  7. 【树形DP/搜索】BZOJ 1827: [Usaco2010 Mar]gather 奶牛大集会

    1827: [Usaco2010 Mar]gather 奶牛大集会 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 793  Solved: 354[Sub ...

  8. bzoj 1914: [Usaco2010 OPen]Triangle Counting 数三角形 容斥

    1914: [Usaco2010 OPen]Triangle Counting 数三角形 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 272  Sol ...

  9. BZOJ 1827: [Usaco2010 Mar]gather 奶牛大集会

    Description Bessie正在计划一年一度的奶牛大集会,来自全国各地的奶牛将来参加这一次集会.当然,她会选择最方便的地点来举办这次集会.每个奶牛居住在 N(1<=N<=100,0 ...

随机推荐

  1. Codeforces Round #327 (Div. 2) B. Rebranding 模拟

    B. Rebranding   The name of one small but proud corporation consists of n lowercase English letters. ...

  2. Web Tab, Project Properties

    https://msdn.microsoft.com/en-us/library/aa983445(v=vs.100).aspx The Web tab of the project Properti ...

  3. JavaScript Patterns 2.4 For-in loop

    Principle Enumeration should be used to iterate over nonarray objects. It's important to use the met ...

  4. 【Poj2960】S-Nim & 博弈论

    Position: http://poj.org/problem?id=2960 List Poj2960 S-Nim List Description Knowledge Solution Noti ...

  5. PCB InCAM 获取 JOB STEP 实现外挂脚本调试功能实现

    PCB CAM自动化基于Incam 打造,在测试时经常遇到调试障碍,每次自行对功能测试时,生成了exe脚本后,再到Incam里面运行,发现问题,再回来修改代码,非常不爽, 参考Genesis调试运行模 ...

  6. codevs3728联合权值(LCA)

    3728 联合权值  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Description 输入描述 Input Des ...

  7. DropDownList 数据源绑定和获取

    前台代码: <td>账户名称:</td> <td> <asp:DropDownList ID="DropDownListAccount" ...

  8. BZOJ 1137 半平面交

    半平面交的板子 //By SiriusRen #include <bits/stdc++.h> #define double long double using namespace std ...

  9. 【Java设计模式】工厂模式

    简单工厂模式 简单工厂模式不是23种里的一种,简而言之,就是有一个专门生产某个产品的类.比如下图中的鼠标工厂,专业生产鼠标,给参数0,生产戴尔鼠标,给参数1,生产惠普鼠标. 示例代码: //一个产品接 ...

  10. Android开发笔记(8)——调用子Activity

     转载请注明:http://www.cnblogs.com/igoslly/p/6853730.html  调用子Activity 需要子Activity返回值 MainActivity使用start ...