题目描述

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.

输入

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.

样例输入

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

样例输出

5
4
5
3
4
4
5
5
5

分析:第二个数据有什么用!?其实就是差分序列嘛,要注意去重。

#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#define range(i,a,b) for(int i=a;i<=b;++i)
#define LL long long
#define rerange(i,a,b) for(int i=a;i>=b;--i)
#define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
using namespace std;
int N,I,H,R,a[],ans;
map<pair<int,int>,bool>vis;
void swap(int &x,int &y){
int tmp=x;
x=y;
y=tmp;
}
void init(){
cin>>N>>I>>H>>R;
range(i,,R){
int x,y;
cin>>x>>y;
if(x>y)swap(x,y);
if(vis[make_pair(x,y)])continue;
vis[make_pair(x,y)]=true;
--a[x+];
++a[y];
}
}
void solve(){
range(i,,N){
ans+=a[i];
cout<<H+ans<<endl;
}
}
int main() {
init();
solve();
return ;
}

Tallest Cow的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  9. poj 3263 Tallest Cow(线段树)

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

随机推荐

  1. 《鸟哥的Linux私房菜》学习笔记(9)——条件判断

    一.条件判断表达式                                                          条件测试类型: 整数测试 字符测试 文件测试 条件测试的表达式 [ ...

  2. pyautogui 模块学习

    在日常实施中,我们用控件对大部分的网页和客户端都能进行拾取操作.但是仍有一小部分的应用无法进行操作.这里我常用到 pyautogui 这个模块.下面做个分享. Python 的 pyautogui 模 ...

  3. hive操作语句

    设置属性: //设置本地执行作set hive.exec.mode.local.auto=true; //设置动态分区 set hive.exec.dynamic.partition=true; se ...

  4. Springmvc 重定向参数传递方式

    Springmvc  通过return "redirect:" 实现重定向   重定向的状态码301  302 301,302 都是HTTP状态的编码,都代表着某个URL发生了转移 ...

  5. mysql之面试问题总结

    问题1.char 与varchar的区别? varchar是变长而char的长度是固定的.如果你的内容是固定的大小,char性能更好. char[4] 与varchar[4]   存储字母a a占一个 ...

  6. Sentry 错误监控

    错误监控:https://sentry.io 支持语言或平台: 

  7. Django补充知识点——用户管理

    内容概要 1.Form表单2.Ajax3.布局,Django母板4.序列化5.Ajax相关6.分页7.XSS攻击8.CSRF9.CBV.FBV 10.类中用装饰器的两种方法 11.上传文件 12.数据 ...

  8. ffmpeg转换参数和对几种视频格式的转换分析

    我们在将多种格式的视频转换成flv格式的时候,我们关注的就是转换后的flv视频的品质和大小.下面就自己的实践所得来和大家分享一下,主要针对avi.3gp.mp4和wmv四种格式来进行分析.通常在使用f ...

  9. Spring AOP Example 文件下载:

      文件下载:http://files.cnblogs.com/wucg/spring_aop_excise.zip P:124 spring核心技术 P225: spring doc 可以把Advi ...

  10. codeforces gym 100553I

    codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...