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. Dubbo服务超时

    服务消费者引用服务提供者的服务时可能由于网络原因导致长时间未返回相应,此时大量的线程将会阻塞,引起性能下降等问题.可以通过引入服务超时来解决该问题 服务超时指服务在给定的时间内未返回相应将立即终止该请 ...

  2. 详解Jquery选择器

    1.常见的选择器 id,类,标签选择器. $("#a1") $(".myclass") $("div") 2.组合选择器 $("# ...

  3. COM口总是有惊叹号怎么办

    现在用win8或者win8.1的人越来越多,搞开发的COM口是离不开的我们用转串口芯片时总会出现COM口有惊叹号的情况,这样我们的设备是无法正常使用的,那要怎么办呢? 方法: 想改成上图这样没有惊叹号 ...

  4. python位运算之计算中位数

    # -*- coding: utf-8 -*- # @Time : 2018/11/23 10:49 PM # @Author : cxa # @File : 1.py # @Software: Py ...

  5. shell script中read的用法

    1.read基本读取 #!/bin/bash #testing the read command echo -n "Enter you name:" #echo -n 让用户直接在 ...

  6. js 将图片连接转换称base64格式

    我们把图像文件的内容直接写在了HTML 文件中,这样做的好处是,节省了一个HTTP 请求.坏处呢,就是浏览器不会缓存这种图像.现在我们提供一个js: function convertImgToBase ...

  7. 16-client、offset、scroll系列

    1.client系列 代码如下: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"& ...

  8. [学习笔记]Javascript采用二进制浮点数和四舍五入的错误

    1.样例 var a = .3 - .2 //0.09999999999999998 var b = .2 - .1 //0.1 a == b //false 出现这样的原因在于 1.Javascri ...

  9. javascript 练习题目答案2

    https://www.liaoxuefeng.com/wiki/001434446689867b27157e896e74d51a89c25cc8b43bdb3000/0014503724525055 ...

  10. web前端开发分享-css,js提高篇

    一. css基础知识掌握之后(个人的标准是:弄清块元素与内联元素的区别,弄清float的应用场景,弄清position[pə'zɪʃən] 下五个属性static['stætɪk],relative[ ...