CF1051G.Distinctification

省选/NOI-

通过率:0%

时间限制:6.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Suppose you are given a sequence SS of kk pairs of integers (a1,b1),(a2,b2),…,(ak,bk)(a_1, b_1), (a_2, b_2), \dots, (a_k, b_k).

You can perform the following operations on it:

  1. Choose some position ii and increase aia_i by 11. That can be performed only if there exists at least one such position jj that i≠ji \ne j and ai=aja_i = a_j. The cost of this operation is bib_i;
  2. Choose some position ii and decrease aia_i by 11. That can be performed only if there exists at least one such position jj that ai=aj+1a_i = a_j + 1. The cost of this operation is −bi-b_i.

Each operation can be performed arbitrary number of times (possibly zero).

Let f(S)f(S) be minimum possible xx such that there exists a sequence of operations with total cost xx, after which all aia_i from SS are pairwise distinct.

Now for the task itself ...

You are given a sequence PP consisting of nn pairs of integers (a1,b1),(a2,b2),…,(an,bn)(a_1, b_1), (a_2, b_2), \dots, (a_n, b_n). All bib_i are pairwise distinct. Let PiP_i be the sequence consisting of the first ii pairs of PP. Your task is to calculate the values of f(P1),f(P2),…,f(Pn)f(P_1), f(P_2), \dots, f(P_n).

假设你得到一个由 kk 个整数对 (a1,b1),(a2,b2),…,(ak,bk)(a_1, b_1), (a_2, b_2), \dots, (a_k, b_k) 构成的序列 SS。

你可以对它执行以下操作:

  1. 选择某个位置 ii,并将 aia_i 增加 11。该操作仅在存在至少一个位置 jj 满足 i≠ji \ne j 且 ai=aja_i = a_j 时才可执行。该操作的代价为 bib_i;
  2. 选择某个位置 ii,并将 aia_i 减少 11。该操作仅在存在至少一个位置 jj 满足 ai=aj+1a_i = a_j + 1 时才可执行。该操作的代价为 −bi-b_i。

每种操作均可执行任意多次(包括零次)。

令 f(S)f(S) 表示满足如下条件的最小可能值 xx:存在一系列总代价恰好为 xx 的操作,使得操作完成后 SS 中所有 aia_i 两两互不相同。

现在进入本题任务本身……

你被给定一个由 nn 个整数对 (a1,b1),(a2,b2),…,(an,bn)(a_1, b_1), (a_2, b_2), \dots, (a_n, b_n) 构成的序列 PP,其中所有 bib_i 两两互不相同。令 PiP_i 表示由 PP 的前 ii 个整数对构成的序列。你的任务是计算 f(P1),f(P2),…,f(Pn)f(P_1), f(P_2), \dots, f(P_n) 的值。

输入格式

The first line contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of pairs in sequence PP.

Next nn lines contain the elements of PP: ii-th of the next nn lines contains two integers aia_i and bib_i (1≤ai≤2⋅1051 \le a_i \le 2 \cdot 10^5, 1≤bi≤n1 \le b_i \le n). It is guaranteed that all values of bib_i are pairwise distinct.

第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)——表示序列 PP 中的数对个数。

接下来 nn 行包含序列 PP 的元素:其中第 ii 行(即接下来的 nn 行中的第 ii 行)包含两个整数 aia_i 和 bib_i(1≤ai≤2⋅1051 \le a_i \le 2 \cdot 10^5,1≤bi≤n1 \le b_i \le n)。保证所有 bib_i 的值两两不同。

输出格式

Print nn integers — the ii-th number should be equal to f(Pi)f(P_i).

输出 nn 个整数——第 ii 个数应等于 f(Pi)f(P_i)。

输入输出样例

  • 输入#1

    5
    1 1
    3 3
    5 5
    4 2
    2 4

    输出#1

    0
    0
    0
    -5
    -16
  • 输入#2

    4
    2 4
    2 3
    2 2
    1 1

    输出#2

    0
    3
    7
    1

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

首页