CF56E.Domino Principle

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vasya is interested in arranging dominoes. He is fed up with common dominoes and he uses the dominoes of different heights. He put n 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. The i-th domino has the coordinate x__i and the height h__i. 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 coordinate x and height h leads to the fall of all dominoes on the segment [x + 1, x + h - 1].

瓦西娅对摆放多米诺骨牌很感兴趣。他厌倦了普通的多米诺骨牌,因此使用了不同高度的多米诺骨牌。他将 nn 个多米诺骨牌沿着一条水平轴从左到右依次摆放在桌面上。每个多米诺骨牌均垂直于该轴放置,且该轴穿过其底面中心。第 ii 个多米诺骨牌的横坐标为 xix_i,高度为 hih_i。现在瓦西娅想知道:若将每个多米诺骨牌向右推倒,最终会有多少个多米诺骨牌倒下?请你帮他解决这个问题。

注意:一个多米诺骨牌仅在被触碰位置严格高于其底面时才会倒下。换言之,初始坐标为 xx、高度为 hh 的多米诺骨牌倒下后,会导致所有位于区间 [x+1, x+h−1][x+1,\,x+h-1] 内的多米诺骨牌也倒下。

输入格式

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

第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5),表示多米诺骨牌的数量。接下来的 nn 行每行包含两个整数 xix_i 和 hih_i(−108≤xi≤108-10^8 \leq x_i \leq 10^8,2≤hi≤1082 \leq h_i \leq 10^8),分别表示每个多米诺骨牌的坐标和高度。任意两个多米诺骨牌不会立于同一点上。

输出格式

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

输出 n 个空格分隔的整数 z__i —— 表示如果瓦西娅将第 i 个骨牌向右推倒(包括该骨牌本身),最终会倒下的骨牌数量。

输入输出样例

  • 输入#1

    4
    16 5
    20 5
    10 10
    18 2

    输出#1

    3 1 4 1
  • 输入#2

    4
    0 10
    1 5
    9 10
    15 10

    输出#2

    4 1 2 1

输入解题思路,AI测评打分。不知道怎么写?

首页