题目描述

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.

给出牛的可能最高身高,然后输入R组数据 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


我们对于每一个输入(x, y),把x+1~y区间减一。
这个模拟一下应该就看出来了,然后用树状数组维护差分序列。
本来想着一发走人,然而只有50分...ri...
这题丧心病狂有重复输入,不判重一半分没有...
好像没必要用树状数组,直接用差分数组,反正也要从头扫一遍...
emm...貌似比我的复杂度优秀,管他呢能过就行...

 
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
inline int read(){
int res=;char ch=getchar();
while(!isdigit(ch))ch=getchar();
while(isdigit(ch)){res=(res<<)+(res<<)+(ch^);ch=getchar();}
return res;
}
int n, H, I, Q;
int tr[];
#define lowbit(x) x&-x
inline void add(int x, int y)
{
while(x <= n)
{
tr[x] += y;
x += lowbit(x);
}
}
inline int ask(int x)
{
int res = ;
while(x)
{
res += tr[x];
x -= lowbit(x);
}
return res;
}
map <pair<int,int>,int>mp; int main()
{
n = read(), I = read(), H = read(), Q = read();
while(Q--)
{
int x = read(), y = read();
if (mp[make_pair(x, y)]) continue;
if(x > y)swap(x, y);
add(x+, -);
add(y, );
mp[make_pair(x, y)] = ;
mp[make_pair(y, x)] = ;
}
for (int i = ; i <= n ; i ++)
{
printf("%d\n",H + ask(i));
}
return ;
}

 

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

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

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

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

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

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

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

  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. 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 ...

  8. 【BZOJ】1635: [Usaco2007 Jan]Tallest Cow 最高的牛(差分序列)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1635 差分序列是个好东西啊....很多地方都用了啊,,, 线性的进行区间操作orz 有题可知 h[a ...

  9. 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 ...

随机推荐

  1. 认识HTML和CSS

    1.认识HTML标记 HTML的全称是Hyper text markup language,超文本标记语言,用于定义文档的内容结构.在HTML中,所有的标记都是成对出现的. <html>标 ...

  2. SpringCloud-Hystrix Dashboard 之 Unable to connect to Command Metric Stream

    实践hystrix dashboard仪表盘的时候,不管是按照书上的还是网上的,都提示Unable to connect to Command Metric Stream. 查了好久发现,如果使用sp ...

  3. [Code] 烧脑之算法模型

    把博客的算法过一遍,我的天呐多得很,爱咋咋地! 未来可考虑下博弈算法. 基本的编程陷阱:[c++] 面试题之犄角旮旯 第壹章[有必要添加Python] 基本的算法思想:[Algorithm] 面试题之 ...

  4. Redis会遇到的问题以及解决方案

    1.缓存雪崩 发生场景:当Redis服务器重启或者大量缓存在同一时期失效时,此时大量的流量会全部冲击到数据库上面,数据库有可能会因为承受不住而宕机 解决办法: 1)随机均匀设置失效时间 2)设置过期标 ...

  5. 品Spring:bean定义上梁山

    认真阅读,收获满满,向智慧又迈进一步... 技术不枯燥,先来点闲聊 先说点好事高兴一下.前段时间看新闻说,我国正式的空间站建设已在进行当中.下半年,长征五号B运载火箭将在海南文昌航天发射场择机将空间站 ...

  6. Android Adapter的一些记录

    一.摘要 An Adapter object acts as a bridge between an AdapterView and the underlying data for that view ...

  7. 安装sublime text3 、转化为汉化版、安装SublimeREPL使得在交互条件下运行代码,设置快捷键

    一.sublime Sublime Text 3是轻量级的,安装包很小,它的大部分功能是依靠丰富的插件实现的,而且占用资源少.目前主流版本是Sublime Text3,在官网就可以下载,http:// ...

  8. 利用Python进行数据分析:【IPython】

    一.IPython基础功能 1.IPython是交互式的Python命令行2.安装与使用 #安装:pip install ipython #使用:ipython与Python解释器的使用方法一致 注: ...

  9. Maven 梳理 - maven新建web项目提示"javax.servlet.http.HttpServlet" was not found on the Java Build Path

    方法一: <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api&l ...

  10. 02-head标签

    head中的标签不会展示在浏览器上,他会将页面的一些额外信息告诉服务器.head标签中包含如下标签: <title>:指定整个网页的标题,在浏览器最上方显示 <meta>:提供 ...