题目

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

分析

因为让求的是每头牛最高多少,我们先假设每头牛都是最高的,然后输入两个数a,b,表示两个数中的每头牛比两边的小,所以就把从a+1到b-1的牛高度-1;这个题数据范围1e4,可以用差分优化,然后就完了。

代码

#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e4+;
int n,m,g,h,a[maxn];
bool v[maxn][maxn];
int main() {
scanf("%d%d%d%d", &n, &h, &g, &m);
for(int i = ; i <= m; i++) {
int x, y;
scanf("%d%d", &x, &y);
if (x > y) swap(x, y);
if (v[x][y]) continue;
v[x][y] = ;
a[x+]--,a[y]++;
}
for(int i = ; i <= n; i++)
a[i] += a[i-], printf("%d\n", a[i] + g);
return ;
}

【差分】Tallest Cow的更多相关文章

  1. bzoj 1635: [Usaco2007 Jan]Tallest Cow 最高的牛——差分

    Description FJ's N (1 <= N <= 10,000) cows conveniently indexed 1..N are standing in a line. E ...

  2. POJ3263 Tallest Cow 差分

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. ActiveMQ 笔记(八)高级特性和大厂常考重点

    个人博客网:https://wushaopei.github.io/    (你想要这里多有) 1.可用性保证 引入消息队列之后该如何保证其高可用性? 持久化.事务.签收. 以及带复制的 Leavel ...

  2. Spring Boot笔记(二) springboot 集成 SMTP 发送邮件

    个人博客网:https://wushaopei.github.io/    (你想要这里多有) 笔记:乘着项目迭代的间隙,把一些可复用的功能从项目中抽取出来,这是其中之一, 一.添加SMTP 及 MA ...

  3. Qcom平台RTC驱动分析

    相关文件list: pm8998.dtsi ---RTC dts配置 qpnp-rtc.c ---qcom RTC驱动 class.c ---RTC相关class interface.c ---相关R ...

  4. Java实现 LeetCode 392 判断子序列

    392. 判断子序列 给定字符串 s 和 t ,判断 s 是否为 t 的子序列. 你可以认为 s 和 t 中仅包含英文小写字母.字符串 t 可能会很长(长度 ~= 500,000),而 s 是个短字符 ...

  5. Java实现蓝桥杯VIP 算法训练 P0504

    试题 算法训练 P0504 资源限制 时间限制:1.0s 内存限制:256.0MB Anagrams指的是具有如下特性的两个单词:在这两个单词当中,每一个英文字母(不区分大小写)所出现的次数都是相同的 ...

  6. Java实现 洛谷 Car的旅行路线

    输入输出样例 输入样例#1: 1 3 10 1 3 1 1 1 3 3 1 30 2 5 7 4 5 2 1 8 6 8 8 11 6 3 输出样例#1: 47.5 import java.util. ...

  7. Android studio怎么导入Recycler VIew

    有可能你导入的RecyclerView只显示一行,是因为导错了包,当时可能没问题,当你用Adapter运行的时候会疯狂报错(别问我怎么知道的,我就是从那里出来的) 首先,打开build.gradle( ...

  8. Java实现字符串的旋转

    1 问题描述 给定一个字符串,要求将字符串前面的若干个字符移到字符串的尾部.例如,将字符串"abcdef"的前3个字符'a'.'b'和'c'移到字符串的尾部,那么原字符串将变成&q ...

  9. Java实现 洛谷 P1200 [USACO1.1]你的飞碟在这儿Your Ride Is He…

    import java.util.Scanner; public class Main{ private static Scanner cin; public static void main(Str ...

  10. java实现取球游戏

    /* 今盒子里有 n 个小球,A.B 两人轮流从盒中取球,每个人都可以看到另一个人取了多少个, 也可以看到盒中还剩下多少个,并且两人都很聪明,不会做出错误的判断. 我们约定: 每个人从盒子中取出的球的 ...