博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C - 思考使用差分简化区间操作
阅读量:5281 次
发布时间:2019-06-14

本文共 1689 字,大约阅读时间需要 5 分钟。

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 (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: NIH and R 

Lines 2.. R+1: Two distinct space-separated integers A and B (1 ≤ AB ≤ 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 51 35 34 33 79 8

Sample Output

545344555

思路:用差分数组维护区间的增减,坑点是有可能出现相同区间,如果出现相同的区间就不用处理了,真坑,wa了,用map标记之前是否出现过

其余应该比较简单

代码:

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define MAX 10005typedef long long ll;using namespace std;map
mp;int a[MAX];int d[MAX];int vis[1000005];int main(){ int N,I,H,R; cin>>N>>I>>H>>R; for(int t=1;t<=N;t++) { a[t]=H; } for(int t=1;t<=N;t++) { d[t]=a[t]-a[t-1]; } int l,r; for(int t=0;t
=2&&mp[l]!=r) { d[min(l,r)+1]--; d[max(l,r)]++; mp[l]=r; } } for(int t=1;t<=N;t++) { a[t]=a[t-1]+d[t]; } for(int t=1;t<=N;t++) { cout<
<

 

转载于:https://www.cnblogs.com/Staceyacm/p/10781798.html

你可能感兴趣的文章
近期项目计划
查看>>
ssh 配置免密失败
查看>>
Python的小技巧小知识
查看>>
jquery.form.js实现异步上传
查看>>
教室里的不速之客-赵广宇
查看>>
linux awk命令详解
查看>>
Isight Linux 2016hf2 安装步骤
查看>>
python selenium 鼠标悬停
查看>>
【HTML】placeholder中换行
查看>>
查看CPU数量和核心数
查看>>
Android异步加载网络图片
查看>>
python学习之 - XML
查看>>
css问题小计
查看>>
Laravel学习笔记(三)数据库 数据库迁移
查看>>
ORACLE查看并修改最大连接数
查看>>
box-flex不均分问题
查看>>
Python--GIL 详解
查看>>
Oracle数据导入Mysql中
查看>>
BZOJ-4424 &&CodeForces-19E Fairy DP+dfs (Link-Cut-Tree可A)
查看>>
MongoDB学习笔记——聚合操作之group,distinct,count
查看>>