To 洛谷.2879 区间统计

题目描述

FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positive integer height (which is a bit of secret). You are told only the height H (1 ≤ H ≤ 1,000,000) of the tallest cow along with the index I of that cow.

FJ has made a list of R (0 ≤ R ≤ 10,000) lines of the form "cow 17 sees cow 34". This means that cow 34 is at least as tall as cow 17, and that every cow between 17 and 34 has a height that is strictly smaller than that of cow 17.

For each cow from 1..N, determine its maximum possible height, such that all of the information given is still correct. It is guaranteed that it is possible to satisfy all the constraints.

给出牛的可能最高身高,然后输入m组数据 a b,代表a,b可以相望,最后求所有牛的可能最高身高输出

输入输出格式

输入格式:

Line 1: Four space-separated integers: N, I, H and R

Lines 2..R+1: Two distinct space-separated integers A and B (1 ≤ A, B ≤ N), indicating that cow A can see cow B.

输出格式:

Lines 1..N: Line i contains the maximum possible height of cow i.

输入输出样例

输入样例#1:

9 3 5 5
1 3
5 3
4 3
3 7
9 8
输出样例#1:

5
4
5
3
4
4
5
5
5

代码:

 #include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
const int N=; int n,i,h,r,S[N],F[N];
map<int,bool>Mp[N]; void read(int &now)
{
now=;char c=getchar();
while(c<''||c>'')c=getchar();
while(c>=''&&c<='')now=(now<<)+(now<<)+c-'',c=getchar();
} int main()
{
read(n);read(i);read(h);read(r);
while(r--)
{
int a,b;
read(a);read(b);
if(a>b) swap(a,b);
if(Mp[a][b])//判重,防止 5-3 和 3-5这种情况
continue;
Mp[a][b]=;
--S[a+];++S[b];//前缀和,该区间-1
}
for(int i=;i<=n;++i)
{
F[i]=S[i]+F[i-];
printf("%d\n",F[i]+h);
}
return ;
}

洛谷P2879 [USACO07JAN]区间统计Tallest Cow的更多相关文章

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

    传送门 题目大意: n头牛,其中最高身高为h,给出r对关系(x,y) 表示x能看到y,当且仅当y>=x并且x和y中间的牛都比 他们矮的时候,求每头牛的最高身高. 题解:贪心+差分 将每头牛一开始 ...

  2. bzoj1635 / P2879 [USACO07JAN]区间统计Tallest Cow

    P2879 [USACO07JAN]区间统计Tallest Cow 差分 对于每个限制$(l,r)$,我们建立一个差分数组$a[i]$ 使$a[l+1]--,a[r]++$,表示$(l,r)$区间内的 ...

  3. [Luogu2879][USACO07JAN]区间统计Tallest Cow

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

  4. 题解 P2879 【[USACO07JAN]区间统计Tallest Cow】

    题目链接: https://www.luogu.org/problemnew/show/P2879 思路: 先不管最大高度,我们读入一对x,y.说明,x+1~y-1之间牛的身高都小于x,y. 然后不妨 ...

  5. [USACO07JAN]区间统计Tallest Cow

    前缀和 sum[i]表示前i个数的和 每次读入a[i]的时候 sum[i] = sum[i - 1] + a[i]; 查询l ~ r区间的和: sum[r] - sum[l - 1] 差分 即前缀和的 ...

  6. [Luogu] 区间统计Tallest Cow

    https://www.luogu.org/problemnew/show/P2879 差分 | 线段树 #include <iostream> #include <cstdio&g ...

  7. 洛谷P1712 [NOI2016]区间 尺取法+线段树+离散化

    洛谷P1712 [NOI2016]区间 noi2016第一题(大概是签到题吧,可我还是不会) 链接在这里 题面可以看链接: 先看题意 这么大的l,r,先来个离散化 很容易,我们可以想到一个结论 假设一 ...

  8. 洛谷 1063 dp 区间dp

    洛谷 1063 dp 区间dp 感觉做完这道提高组T1的题之后,受到了深深的碾压,,最近各种不在状态.. 初看这道题,不难发现它具有区间可并性,即(i, j)的最大值可以由(i, k) 与 (k+1, ...

  9. BZOJ5259/洛谷P4747: [Cerc2017]区间

    BZOJ5259/洛谷P4747: [Cerc2017]区间 2019.8.5 [HZOI]NOIP模拟测试13 C.优美序列 思维好题,然而当成NOIP模拟题↑真的好吗... 洛谷和BZOJ都有,就 ...

随机推荐

  1. 【转载】apache log配置 按日期写日志

    指定apache日志每天生成一个文件 Linux系统配置方法 在apache的配置文件httpd.conf中找到 代码如下1 ErrorLog logs/error_log CustomLog log ...

  2. Libevent源码分析—从使用Libevent库开始

    练习libevent库的使用,主要是几个API的调用顺序.根据event.h的开头注释部分可知,要使用libevent库,主要的几个API及调用顺序为:         event_base()初始化 ...

  3. 功率 dbm 和 mw 的换算

    射频知识; 功率/电平(dBm):放大器的输出能力,一般单位为w.mw.dBm.dBm是取1mw作基准值,以分贝表示的绝对功率电平. 换算公式:电平(dBm)=10lgw5W  → 10lg5000  ...

  4. MariaDB基于GTID主从复制及多主复制

    一.简单主从模式配置步骤(必须要mysql5.6,此处以maridb10.0.10为例) 1.配置主从节点的服务配置文件 # vim /etc/my.cnf 1.1.配置master节点: [mysq ...

  5. windows10+mysql8.0.11zip安装

    准备: MySQL8.0 Windows zip包下载地址:https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.11-winx64.zip 环境: ...

  6. Date对象和Time对象

    方法 描述  getDate()  : setDate()  返回/设置月份中的日期(1-31)  getDay()  返回星期几(0-6)  getFullYear():setFullYear() ...

  7. 使用spring-boot-starter-data-jpa 怎么配置使运行时输出SQL语句

    在 application.properties 中加入以下配置 spring.jpa.show-sql=true

  8. javafx点击鼠标出现弹窗,demo

    在学习javafx的过程中,不知道怎么出现一个弹窗,如,点击一个按钮出现一个修改信息的列表选项 终于在javafx文档示例中发现了类似的东西,记录一下,备忘package demo9_button; ...

  9. ERP合同管理二(三十)

    未审核表单列表显示: 1.用户登录后,根据登录用户加载审核流程表中属于当前登录用户的未审核表单.2.点击选中未审核表单跳转到指定审核流程页面 if (Request.QueryString[" ...

  10. bind this指针

    var TEST = { msg: 'test', ping: function() { return this.msg }.bind(this /* this -> window */) }