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.

Input

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.

Output

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

Sample Input

9 3 5 5
1 3
5 3
4 3
3 7
9 8

Sample Output

5
4
5
3
4
4
5
5
5 题意:n头牛 第i个牛最高,高度为h
然后有r个关系 说明这个关系中的两头牛相互看的见(他们中间的牛高度比他们矮)
求所有牛最大可能的高度 思路:
1、既然给出每个关系中x、y两头牛相互可以看见,那么他们之间的牛的高度肯定比他要矮,所以每次给出x、y,我们只需要将x+1到y-1的牛高度全部-1,这样最后就知道了他们之间的最小高度差,
再把每个cow【i】+h O(NR)
2、我们可以优化一下,就是说给你x、y两头牛,你在x+1的位置-1,再y的位置+1,这样我们就记录了这个关系,你从x遍历到y,让cow【i】+=cow【i-1】,你会发现,他每个x+1到y-1都是-1而x、y则是0,
我们可以把所有的关系先记录下来,然后遍历就可以知道他们之间的最小高度差,然后cow【i】+h O(N+R) 坑点:记得去重
 #include<cstdio>
#include<iostream>
#include<map>
using namespace std;
typedef pair<int,int> P;
const int maxn = 1e4+;
int n,i,h,r;
int ans[maxn];
map<P,int>mp;
int main()
{
scanf("%d%d%d%d",&n,&i,&h,&r);
for(int i=;i<=r;i++)
{
int x,y;
scanf("%d%d",&x,&y);
if(x > y)swap(x,y);
if(mp[P(x,y)])continue;
mp[P(x,y)]=;
for(int j=x+;j<y;j++)
{
ans[j]--;
} }
for(int i=;i<=n;i++)
{
printf("%d\n",ans[i]+h);
}
}
 #include<cstdio>
#include<iostream>
#include<map>
using namespace std;
typedef pair<int,int> P;
const int maxn = 1e4+;
int n,i,h,r;
int ans[maxn];
map<P,int>mp;
int main()
{
scanf("%d%d%d%d",&n,&i,&h,&r);
for(int i=;i<=r;i++)
{
int x,y;
scanf("%d%d",&x,&y);
if(x > y)swap(x,y);
if(mp[P(x,y)])continue;
mp[P(x,y)]=;
ans[x+]--;
ans[y]++;
}
for(int i=;i<=n;i++)
{
ans[i] += ans[i-];
printf("%d\n",ans[i]+h);
}
}

Tallest Cow POJ - 3263 (区间点修改)的更多相关文章

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

  2. poj 3263 Tallest Cow(线段树)

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

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

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

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

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

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

  6. poj3263 Tallest Cow

    题意略去. 考虑给定的R对pair(A, B). 即A能看见B,这意味着B不比A低,并且区间内部的所有元素的高度严格小于A的高度. 我们规定区间的方向:若A > B,为反方向,反之称为正方向. ...

  7. POJ 3264 区间最大最小值Sparse_Table算法

    题目链接:http://poj.org/problem?id=3264 Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total ...

  8. poj 3264 区间最大最小值 RMQ问题之Sparse_Table算法

    Balanced Lineup Time Limit: 5000 MS Memory Limit: 0 KB 64-bit integer IO format: %I64d , %I64u Java ...

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

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

随机推荐

  1. git的学习笔记(一):git本地操作

    1.Git介绍 Git是一个开源的分布式版本控制软件,用以有效.高速的处理从很小到非常大的项目版本管理. Git 最初是由Linus Torvalds设计开发的,用于管理Linux内核开发. Git ...

  2. 本文转自 MyEclipse 2015反编译插件安装

    本文转自MyEclipse 2015反编译插件安装 分享一下下载插件的地址,百度网盘:链接:http://pan.baidu.com/s/1nturiAH 密码:yk73 其次:我来说下具体操作步骤: ...

  3. Confluence 6 缓存性能优化

    Confluence 的运行状态与缓存状态有这密切的关系.针对 Confluence 的管理员来说,尤其是大型站点的 Confluence 管理员,设置好缓存尤其显得关键. 希望修改缓存的大小: 进入 ...

  4. Linux 用户(user)和用户组(group)管理概述

    一.理解Linux的单用户多任务,多用户多任务概念: Linux 是一个多用户.多任务的操作系统:我们应该了解单用户多任务和多用户多任务的概念: 1.Linux 的单用户多任务:单用户多任务:比如我们 ...

  5. LeetCode(125):验证回文串

    Easy! 题目描述: 给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写. 说明:本题中,我们将空字符串定义为有效的回文串. 示例 1: 输入: "A man, ...

  6. ZenMap扫描笔记

    1.软件界面如下,ZenMap 扫描工具是kali linu中对WEB渗透扫描的一款工具

  7. Web前端渗透测试技术小结(一)

    首先端正一下态度不可干违法的事 1.SQL注入测试 对于存在SQL注入的网页,使用SQL语句进行关联查询(仿照C/S模式)eg   http://www.foo.com/user.php?id=1 常 ...

  8. hdu2121 最小树形图的虚根

    /* 最小树形图的第二题,终于有了一些理解 具体看注释 */ /* 无定根的最小树形图 建立虚root 每次只找最短的那条入边 最小树形图理解: 第一步:寻找最短弧集E:扫一遍所有的边,找到每个点权值 ...

  9. 使用git克隆项目、从dev分支上更新代码以及将代码提交到Coding(或GitHub)上面

    本教程的目的: 这是个crm项目中,有两个分支一个是master 和 dev ,master主分支,不允许提交代码,我要拉去dev分支上最新的代码,并将修改后的项目,在推送到dev分支上. 一. 1. ...

  10. json数据转为Map集合

    我是利用Gson来弄得Gson gson = new Gson();//显得出HashMap的类型Type type = new TypeToken<HashMap<String, Str ...