CF1051G.Distinctification
省选/NOI-
通过率:0%
时间限制:6.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Suppose you are given a sequence S of k pairs of integers (a1,b1),(a2,b2),…,(ak,bk).
You can perform the following operations on it:
- Choose some position i and increase ai by 1. That can be performed only if there exists at least one such position j that i=j and ai=aj. The cost of this operation is bi;
- Choose some position i and decrease ai by 1. That can be performed only if there exists at least one such position j that ai=aj+1. The cost of this operation is −bi.
Each operation can be performed arbitrary number of times (possibly zero).
Let f(S) be minimum possible x such that there exists a sequence of operations with total cost x, after which all ai from S are pairwise distinct.
Now for the task itself ...
You are given a sequence P consisting of n pairs of integers (a1,b1),(a2,b2),…,(an,bn). All bi are pairwise distinct. Let Pi be the sequence consisting of the first i pairs of P. Your task is to calculate the values of f(P1),f(P2),…,f(Pn).
假设你得到一个由 k 个整数对 (a1,b1),(a2,b2),…,(ak,bk) 构成的序列 S。
你可以对它执行以下操作:
- 选择某个位置 i,并将 ai 增加 1。该操作仅在存在至少一个位置 j 满足 i=j 且 ai=aj 时才可执行。该操作的代价为 bi;
- 选择某个位置 i,并将 ai 减少 1。该操作仅在存在至少一个位置 j 满足 ai=aj+1 时才可执行。该操作的代价为 −bi。
每种操作均可执行任意多次(包括零次)。
令 f(S) 表示满足如下条件的最小可能值 x:存在一系列总代价恰好为 x 的操作,使得操作完成后 S 中所有 ai 两两互不相同。
现在进入本题任务本身……
你被给定一个由 n 个整数对 (a1,b1),(a2,b2),…,(an,bn) 构成的序列 P,其中所有 bi 两两互不相同。令 Pi 表示由 P 的前 i 个整数对构成的序列。你的任务是计算 f(P1),f(P2),…,f(Pn) 的值。
输入格式
The first line contains a single integer n (1≤n≤2⋅105) — the number of pairs in sequence P.
Next n lines contain the elements of P: i-th of the next n lines contains two integers ai and bi (1≤ai≤2⋅105, 1≤bi≤n). It is guaranteed that all values of bi are pairwise distinct.
第一行包含一个整数 n(1≤n≤2⋅105)——表示序列 P 中的数对个数。
接下来 n 行包含序列 P 的元素:其中第 i 行(即接下来的 n 行中的第 i 行)包含两个整数 ai 和 bi(1≤ai≤2⋅105,1≤bi≤n)。保证所有 bi 的值两两不同。
输出格式
Print n integers — the i-th number should be equal to f(Pi).
输出 n 个整数——第 i 个数应等于 f(Pi)。
输入输出样例
输入#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测评打分。不知道怎么写?