http://www.lydsy.com/JudgeOnline/problem.php?id=1635

差分序列是个好东西啊。。。。很多地方都用了啊,,,

线性的进行区间操作orz

有题可知

h[a+1]~a[b-1]都是比h[a]和h[b]小,那么最佳方案就是将次区间的所有高度-1,那么我们就将整个区间-1

也就是sum[a+1]--, sum[b]++

而条件h[a]>=h[b]我还不明觉厉啊。。。。。

(脑补:假设一般情况下h[a]==h[b]的,而却有c使得(a, c), pos[c]>pos[b],那么这样b显然比a和c低,这样h[a]==h[b]的情况就打破了,也就是我们按照交换过来后的差分是成立的)

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cmath>
  4. #include <string>
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <queue>
  8. using namespace std;
  9. #define rep(i, n) for(int i=0; i<(n); ++i)
  10. #define for1(i,a,n) for(int i=(a);i<=(n);++i)
  11. #define for2(i,a,n) for(int i=(a);i<(n);++i)
  12. #define for3(i,a,n) for(int i=(a);i>=(n);--i)
  13. #define for4(i,a,n) for(int i=(a);i>(n);--i)
  14. #define CC(i,a) memset(i,a,sizeof(i))
  15. #define read(a) a=getint()
  16. #define print(a) printf("%d", a)
  17. #define dbg(x) cout << #x << " = " << x << endl
  18. #define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
  19. inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
  20. inline const int max(const int &a, const int &b) { return a>b?a:b; }
  21. inline const int min(const int &a, const int &b) { return a<b?a:b; }
  22.  
  23. const int N=10005;
  24. int f[N], n, h, r;
  25. struct dat { int x, y; }a[N];
  26. bool cmp(const dat &a, const dat &b) { return a.x==b.x?a.y<b.y:a.x<b.x; }
  27. int main() {
  28. int tp;
  29. read(n); read(tp); read(h); read(r);
  30. for1(i, 1, r) {
  31. int x=getint(), y=getint();
  32. if(y<x) swap(x, y); a[i].x=x, a[i].y=y;
  33. }
  34. sort(a+1, a+1+r, cmp);
  35. a[0].x=-10;
  36. for1(i, 1, r) {
  37. if(a[i].x==a[i-1].x && a[i].y==a[i-1].y) continue;
  38. --f[a[i].x+1]; ++f[a[i].y];
  39. }
  40. int sum=0;
  41. for1(i, 1, n) {
  42. sum+=f[i];
  43. printf("%d\n", h+sum);
  44. }
  45. return 0;
  46. }

Description

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.

有n(1 <= n <= 10000)头牛从1到n线性排列,每头牛的高度为h[i](1 <= i <= n),现在告诉你这里面的牛的最大高度为maxH,而且有r组关系,每组关系输入两个数字,假设为a和b,表示第a头牛能看到第b头牛,能看到的条件是 a, b之间的其它牛的高度都严格小于min(h[a], h[b]),而h[b] >= h[a]

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

INPUT DETAILS:

There are 9 cows, and the 3rd is the tallest with height 5.

Sample Output

5
4
5
3
4
4
5
5
5

HINT

Source

【BZOJ】1635: [Usaco2007 Jan]Tallest Cow 最高的牛(差分序列)的更多相关文章

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

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

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

  3. bzoj 1635: [Usaco2007 Jan]Tallest Cow 最高的牛【差分】

    s[i]为差分后的"i这头牛前有几头比它高",计算答案的时候加成前缀和,假设第一头最高减一下即可 用map记录一下被加过的区间,避免重复 #include<iostream& ...

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

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

  5. 【BZOJ】1635: [Usaco2007 Jan]Tallest Cow 最高的牛

    [题意]n头牛,其中最高h.给定r组关系a和b,要求满足h[b]>=h[a]且a.b之间都小于min(h[a],h[b]),求第i头牛可能的最高高度. [算法]差分 [题解]容易发现r组关系只能 ...

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

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

  7. bzoj 1701 [Usaco2007 Jan]Cow School牛学校

    [Usaco2007 Jan]Cow School牛学校 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 175  Solved: 83[Submit][S ...

  8. bzoj 1636: [Usaco2007 Jan]Balanced Lineup -- 线段树

    1636: [Usaco2007 Jan]Balanced Lineup Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 772  Solved: 560线 ...

  9. BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花( 贪心 )

    考虑相邻的两头奶牛 a , b , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...

随机推荐

  1. Linux crond实例

    linux系统的定时任务: 1:linux系统自身定期执行的任务工作:系统周期性执行的任务工作,如轮询系统日志,备份系统数据,清理系统缓存等. [root@10-4-5-9 ~]# ll /var/l ...

  2. android studio提示信息乱码解决方法

    在build.gradle文件中加上 android {compileOptions.encoding = "GBK"}就好了

  3. Loadrunner中影响"响应时间"的设置

    1.Runtime setting的设置 *Think time 这个就不多说了,如果忽略则"响应时间"会变短,但同时对服务器的压力增大,从而间接影响响应时间 在anlaysis里 ...

  4. js处理url

    需求:用js获得url的电话号码和状态 针对url地址:http://www.deikang.com/index.php?tel=15811296111&status=1&id=100 ...

  5. STM32出现HardFault故障的解决方法

    https://wenku.baidu.com/view/a4a7499afad6195f312ba6d2.html https://wenku.baidu.com/view/085b6fbe5022 ...

  6. javascript、js操作json对象和字符串互相转换方法

    相信前端的同学们对json并不陌生,接触过很多.但是很少人知道json的全称是什么,哈哈,我也是查资料知道的.(JSON JavaScript Object Notation是一种轻量级的数据交换格式 ...

  7. Mysql 逻辑运算符详解

    逻辑运算符又称为布尔运算符,用来确认表达式的真和假.MySQL 支持4 种逻辑运算符,如表4-3 所示. 表4-3                          MySQL 中的逻辑运算符 运算符 ...

  8. 关于php使用基于socket Web消息推送(未完)

    转:http://blog.csdn.net/young_phper/article/details/52441143 http://www.workerman.net/ http://blog.cs ...

  9. [转]C#如何判断操作系统位数是32位还是64位

    方法一: 对于C#来说,调用WMI是一种简单易行的方式.我们可以用Win32_Processor类里面的AddressWidth属性来表示系统的位宽.AddressWidth的值受CPU和操作系统的双 ...

  10. RPC服务框架dubbo(一):简介和原理解析

    前置概念 在学习dubbo前,需要先了解SOA和RPC这两个概念. SOA 1.英文名称(Service Oriented Ambiguity) 2.中文名称:面向服务架构 2.1 有一个专门提供服务 ...