CodeForces 56E-Find the Path(技巧)

Description

Vasya is interested in arranging dominoes. He is fed up with common dominoes and he uses the dominoes of different heights. He putn dominoes on the table along one axis, going from left to right. Every domino stands perpendicular to that axis so that the axis passes through the center of its base. Thei-th domino has the coordinate xi and the height hi. Now Vasya wants to learn for every domino, how many dominoes will fall if he pushes it to the right. Help him do that.

Consider that a domino falls if it is touched strictly above the base. In other words, the fall of the domino with the initial coordinatex and height h leads to the fall of all dominoes on the segment[x + 1, x + h - 1].

CodeForces 56E-Find the Path(技巧)_第1张图片

Input

The first line contains integer n (1 ≤ n ≤ 105) which is the number of dominoes. Then follown lines containing two integers xi and hi ( - 108 ≤ xi ≤ 108, 2 ≤ hi ≤ 108) each, which are the coordinate and height of every domino. No two dominoes stand on one point.

Output

Print n space-separated numbers zi — the number of dominoes that will fall if Vasya pushes thei-th domino to the right (including the domino itself).

Sample Input

Input
4
16 5
20 5
10 10
18 2
Output
3 1 4 1 
Input
4
0 10
1 5
9 10
15 10
Output
4 1 2 1 

                                                                                                    

题意:给出多米诺骨牌所在的x 轴和高h,求出每一个多米诺骨牌向右倒下时能使多少的牌倒下。

思路:使用数组将每一个牌能够使右边的牌倒下的的数目记录下来,在操作的时候要使用一点小技巧才能不T,具体看代码

CODE:

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
const int inf=0xfffffff;
typedef long long ll;
using namespace std;

const int Max=100005;
struct node
{
    int x,h,d;
    int sum;
    int id;
}dom[Max];

bool cmp(node a,node b)
{
    return a.x=0;i--){
            int t=i+1;
            dom[i].sum=1;
            while(dom[i].d>dom[t].x && t


你可能感兴趣的:(杂题)