一个压了很久的题目,确实很难想,看了别人的做法后总算明白了。

首先要明白一点,因为题目说明了不会有矛盾,所以题目给出来的区间是不能相交的,否则是矛盾的。(原因自己想)

然后既然区间只能是包含的,就很明显了,一个数被包含了几次它就要比最高的牛矮多少。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1e4+9;
struct D
{
int l,r;
bool operator <(const struct D & xx) const
{
if(l==xx.l)
return r<xx.r;
return l<xx.l;
}
}qry[maxn];
int dp[maxn];
int main()
{
int n,m,h,r;
scanf("%d %d %d %d",&n,&m,&h,&r);
for(int i=1;i<=r;i++)
{
scanf("%d %d",&qry[i].l,&qry[i].r);
if(qry[i].l>qry[i].r)
swap(qry[i].l,qry[i].r);
}
sort(qry+1,qry+1+r);
qry[0].l=0;
for(int i=1;i<=r;i++)
{
if(qry[i].l==qry[i-1].l&&qry[i].r==qry[i-1].r)
continue;
dp[qry[i].l+1]--;
dp[qry[i].r]++;
}
int ret=0;
for(int i=1;i<=n;i++)
{
ret+=dp[i];
printf("%d\n",ret+h);
}
return 0;
}

poj 3263 Tallest Cow的更多相关文章

  1. poj 3263 Tallest Cow(线段树)

    Language: Default Tallest Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1964   Ac ...

  2. POJ 3263 Tallest Cow 题解

    题目 FJ's \(N (1 ≤ N ≤ 10,000)\) cows conveniently indexed 1..N are standing in a line. Each cow has a ...

  3. 【差分】POJ 3263 Tallest Cow

    题目大意 POJ链接 给出\(n\)头牛的身高,和\(m\)对关系,表示牛\(a[i]\)与\(b[i]\)可以相互看见.已知最高的牛为第\(p\)头,身高为\(h\). 求每头牛的身高最大可能是多少 ...

  4. Tallest Cow POJ - 3263 (区间点修改)

    FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positi ...

  5. POJ 3617 Best Cow Line(最佳奶牛队伍)

    POJ 3617 Best Cow Line Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] FJ is about to t ...

  6. BZOJ1635: [Usaco2007 Jan]Tallest Cow 最高的牛

    1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 346  Solved: 184 ...

  7. BZOJ 1635: [Usaco2007 Jan]Tallest Cow 最高的牛

    题目 1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec  Memory Limit: 64 MB Description FJ's N ( ...

  8. 1635: [Usaco2007 Jan]Tallest Cow 最高的牛

    1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 383  Solved: 211 ...

  9. 洛谷P2879 [USACO07JAN]区间统计Tallest Cow

    To 洛谷.2879 区间统计 题目描述 FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..N are standing in a line. ...

随机推荐

  1. SiteMesh

    1.导入对SiteMesh.jar的依赖 <dependency>      <groupId>org.sitemesh</groupId>      <ar ...

  2. matrix67:kmp算法详解

    个人认为KMP是最没有必要讲的东西,因为这个东西网上能找到很多资料.但网上的讲法基本上都涉及到“移动(shift)”.“Next函数”等概念,这非常容易产生误解(至少一年半前我看这些资料学习KMP时就 ...

  3. Vijos P1680距离

    题目 背景 简单的DP 描述 设有字符串X,我们称在X的头尾及中间插入任意多个空格后构成的新字符串为X的扩展串,如字符串X为”abcbcd”,则字符串“abcb_c_”,“_a_bcbcd_”和“ab ...

  4. 数据结构——AVL平衡树

    1.是二叉搜索树(Binary Search Tree) 2.树和所有左右子树高度之差为-1,0,1 平衡因子(balance factor) =右子树高度-左子树高度 平衡化旋转: 1.从插入位置向 ...

  5. 循环之while

  6. 在优化SQL语句中使用虚拟索引

    定义:虚拟索引(virtual index) 是指没有创建对应的物理段的索引. 虚拟索引的目的:是在不损耗主机CPU,IO,磁盘空间去实际创建索引的情况下,来判断一个索引是否能够对SQL优化起到作用. ...

  7. vijos 1115 火星人

    说了那么多.事实上就是遍历全排列 #include<iostream> #include<cstdio> #include<algorithm> #include& ...

  8. 为joomla加入�下拉菜单的方法

    用 Joomla! 建站的大多数站长都须要在站点前台使用下拉菜单(dropdown menu),或者叫弹出菜单(slide menu),由于这样能够在有限的页面空间上公布很多其它的导航菜单,而且能够进 ...

  9. android Graphics(四):canvas变换与操作

    前言:前几篇讲解了有关canvas绘图的一些操作,今天更深入一些,讲讲对画布的操作,这篇文章不像前几篇那么容易理解,如果以前没有接触过画布的童鞋可能比较难以理解,为什么会这样.我尽量多画图,让大家更清 ...

  10. UVA610 - Street Directions(Tarjan)

    option=com_onlinejudge&Itemid=8&category=153&page=show_problem&problem=551"> ...