C.Distribution Center---(dp)2016筑波区域赛

Distribution Center

题目链接http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2293

Description

The factory of the Impractically Complicated Products Corporation has many manufacturing lines and the same number of corresponding storage rooms. The same number of conveyor lanes are laid out in parallel to transfer goods from manufacturing lines directly to the corresponding storage rooms. Now, they plan to install a number of robot arms here and there between pairs of adjacent conveyor lanes so that goods in one of the lanes can be picked up and released down on the other, and also in the opposite way. This should allow mixing up goods from different manufacturing lines to the storage rooms. Depending on the positions of robot arms, the goods from each of the manufacturing lines can only be delivered to some of the storage rooms. Your task is to find the number of manufacturing lines from which goods can be transferred to each of the storage rooms, given the number of conveyor lanes and positions of robot arms

Input

The input consists of a single test case, formatted as follows.
n m
x1 y1
.
.
.
xm ym
An integer n (2 ≤ n ≤ 200000) in the first line is the number of conveyor lanes. The lanes are numbered from 1 to n, and two lanes with their numbers differing with 1 are adjacent. All of them start from the position x = 0 and end at x = 100000. The other integer m (1 ≤ m < 100000) is the number of robot arms. The following m lines indicate the positions of the robot arms by two integers xi (0 < xi < 100000) and yi (1 ≤ yi < n). Here, xi is the x-coordinate of the i-th robot arm, which can pick goods on either the lane yi or the lane yi + 1 at position x = xi , and then release them on the other at the same x-coordinate. You can assume that positions of no two robot arms have the same x-coordinate, that is, xi ≠ xj for any i ≠ j

在这里插入图片描述

Output

Output n integers separated by a space in one line. The i-th integer is the number of the manufacturing lines from which the storage room connected to the conveyor lane i can accept goods.

Sample Input

4 3
1000 1
2000 2
3000 3

Sample Output

2 3 4 4


题目大意:给你m个机器臂(只能上下动)的坐标,x,y,它们在第y+1个传送带上,它们可将自己的物品传给上一个,也可以将上一个传送带的物品拿到下面来。问你每个传送带最终能够有多少种物品。
emmm,注意这一题每个传送带可能有多个机器臂。我们可以发现每个传送带上的物品的编号绝对是连续的,那么该传送带上的最终物品种数就是最大的物品编号-最小的物品编号+1。但是由于机械臂只能上下移动,所以假如机械臂后面增加了物品种数,它并不能将它传上去,所以我们要按照x的位置排序,如果前面增加了,那么我们一定可以将它传上去。so这道题也就over了。。。
以下是详细代码:

#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
struct node 
{
	int pos,line;
	bool friend operator <(node a,node b){
		return a.pos<b.pos;
	}
}a[200050];
int dp[200050][3];
int main()
{
	int n,m;
	scanf ("%d%d",&n,&m);
	for (int i=1; i<=m; i++){
		scanf ("%d%d",&a[i].pos,&a[i].line);
		a[i].line++;
	}
	sort(a+1,a+1+m);
	for (int i=1; i<=n; i++) {
		dp[i][1]=dp[i][0]=i;//初始化每层的最大最小编号为自身
	}
	for (int i=1; i<=m; i++){
		int x=a[i].line;
		dp[x-1][1]=dp[x][1];//将该层的最大编号传给上一层
		dp[x][0]=dp[x-1][0];//将上一层的最小编号传给该层
	}
	for (int i=1; i<n; i++){
		printf ("%d ",dp[i][1]-dp[i][0]+1);
	}
	printf ("%d\n",dp[n][1]-dp[n][0]+1);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_43906000/article/details/89058178