[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 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.
输入输出样例
9 3 5 5
1 3
5 3
4 3
3 7
9 8
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的更多相关文章
- bzoj1635 / P2879 [USACO07JAN]区间统计Tallest Cow
P2879 [USACO07JAN]区间统计Tallest Cow 差分 对于每个限制$(l,r)$,我们建立一个差分数组$a[i]$ 使$a[l+1]--,a[r]++$,表示$(l,r)$区间内的 ...
- 洛谷P2879 [USACO07JAN]区间统计Tallest Cow
To 洛谷.2879 区间统计 题目描述 FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..N are standing in a line. ...
- 洛谷 P2879 [USACO07JAN]区间统计Tallest Cow
传送门 题目大意: n头牛,其中最高身高为h,给出r对关系(x,y) 表示x能看到y,当且仅当y>=x并且x和y中间的牛都比 他们矮的时候,求每头牛的最高身高. 题解:贪心+差分 将每头牛一开始 ...
- 题解 P2879 【[USACO07JAN]区间统计Tallest Cow】
题目链接: https://www.luogu.org/problemnew/show/P2879 思路: 先不管最大高度,我们读入一对x,y.说明,x+1~y-1之间牛的身高都小于x,y. 然后不妨 ...
- [USACO07JAN]区间统计Tallest Cow
前缀和 sum[i]表示前i个数的和 每次读入a[i]的时候 sum[i] = sum[i - 1] + a[i]; 查询l ~ r区间的和: sum[r] - sum[l - 1] 差分 即前缀和的 ...
- [Luogu] 区间统计Tallest Cow
https://www.luogu.org/problemnew/show/P2879 差分 | 线段树 #include <iostream> #include <cstdio&g ...
- 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 ...
- 【BZOJ】1635: [Usaco2007 Jan]Tallest Cow 最高的牛(差分序列)
http://www.lydsy.com/JudgeOnline/problem.php?id=1635 差分序列是个好东西啊....很多地方都用了啊,,, 线性的进行区间操作orz 有题可知 h[a ...
- 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 ...
随机推荐
- java 手机号码+邮箱的验证
import java.util.regex.Pattern; //导入的包 1:String REGEX_MOBILE = "^((17[0-9])|(14[0-9])|(13[0-9]) ...
- input和btton的相互使用————小程序
input和btton的相互使用----小程序 index.js data: { userxx:'1111', }, changeSum(){ // this.data.userxx="ch ...
- js-数据交互--AJAX
一:介绍 今天跟下大家简单的介绍一下,在前端开发中,前后端数据交互的一种手段,我们都知道,在前端往后端传送数据的话,利用get,post方法即可向后端发送数据,后端将数据接受,链接到数据库,进行数据库 ...
- Windows导出文件夹中的文件名列表
在需要导出的目录中,shift+右键,打开cmd或者powershell 运行命令:dir -name >list.txt 刷新文件夹,打开list.txt
- PyCharm设置自己的默认模板
1.File-Settings 2.Editor- Code Style - File and Code Templates - Python Script 需要设置什么内容,现在就可以写入了,相关变 ...
- SpringMVC 图片上传虚拟目录
可以直接在tomcat的server.xml文件中进行设置,位置在Host中 添加内容为:<Context docBase="G:\JAVAtest\temp" path=& ...
- 【django】ajax,上传文件,图片预览
1.ajax 概述: AJAX = 异步 JavaScript 和 XML. AJAX 是一种用于创建快速动态网页的技术. 通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新.这意味 ...
- 重学JavaScript之面向对象的程序设计(继承)
1. 继承 ES 中只支持实现继承,而且其实现继承主要依靠原型链来实现的. 2. 原型链 ES中 描述了 原型链的概念,并将原型链作为实现继承的主要方法.其基本思想是利用原型让一个引用类型继承另一个引 ...
- 站内搜索(ELK)之开篇
因工作需要,近期使用ELK搭建单位内部“站内搜索”,目前已将内部OA系统20余个流程的表单.附件的数据索引到elasticsearch中,包括打印复印流程.声像采集流程.远程文件发送.规章制度.内线电 ...
- css或Angular框架限制文本字数
提需求的来了 某一期产品迭代时,新增了一个小功能,即:在单元格中的文本内容,字符超过20个字的时候,需要截断,并显示20个字符+一个省略号,未超过,无视. 这需求看上去不怎么复杂,看起来可以用css做 ...