AT_agc077_f.Two Types of Tasks Editorial
入门
通过率:0%
时间限制:5.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are N jobs numbered 1 through N, and you want to complete them over N days. You perform exactly one job per day.
Job i can be performed on any day from day Li through day Ri. Here, the following conditions are guaranteed to hold for Li and Ri:
- 1≤Li≤i≤Ri≤N
- 1≤L1≤L2≤⋯≤LN≤N
- 1≤R1≤R2≤⋯≤RN≤N
Particularly, from the first condition, it follows that it is possible to complete all N jobs over N days.
Furthermore, each job has a type of L or R. Initially, all jobs are of type R.
The cost of performing a job is defined as follows:
- Suppose job i is performed on day xi. If job i is of type
L, the cost is defined as xi−Li; if it is of typeR, the cost is defined as Ri−xi.
From now on, there will be N queries that change the type of a job to L. In the i-th query, the type of job Pi is changed to L.
For each k=0,1,…,N, solve the following problem:
- Consider the state after processing the first k queries. Find the minimum possible total cost of all N jobs.
有 N 个编号为 1 至 N 的任务,你需要在 N 天内完成它们。每天恰好执行一个任务。
任务 i 可以在第 Li 天至第 Ri 天之间的任意一天执行。其中,Li 和 Ri 满足以下条件:
- 1≤Li≤i≤Ri≤N
- 1≤L1≤L2≤⋯≤LN≤N
- 1≤R1≤R2≤⋯≤RN≤N
特别地,由第一个条件可知,一定存在一种方案可在 N 天内完成全部 N 个任务。
此外,每个任务的类型为 L 或 R。初始时,所有任务的类型均为 R。
执行任务的成本定义如下:
- 假设任务 i 在第 xi 天执行。若任务 i 的类型为
L,则其成本为 xi−Li;若为R,则其成本为 Ri−xi。
接下来将进行 N 次查询,每次将某个任务的类型更改为 L。在第 i 次查询中,任务 Pi 的类型被更改为 L。
对每个 k=0,1,…,N,求解以下问题:
- 考虑处理完前 k 次查询后的状态,求所有 N 个任务的最小可能总成本。
输入格式
The input is given from Standard Input in the following format:
N L1 R1 L2 R2 ⋮ LN RN P1 P2 … PN
输入从标准输入中按以下格式给出:
N L1 R1 L2 R2 ⋮ LN RN P1 P2 … PN
输出格式
For each k=0,1,2,…,N, output the answer in this order, separated by spaces.
对于每个 k=0,1,2,…,N,按此顺序输出答案,用空格分隔。
输入输出样例
输入#1
3 1 3 1 3 2 3 2 1 3
输出#1
3 1 1 2
输入#2
4 1 4 2 4 3 4 4 4 1 2 3 4
输出#2
6 3 1 0 0
输入#3
8 1 5 1 5 2 6 2 6 3 7 3 8 5 8 5 8 5 8 7 3 2 6 4 1
输出#3
17 13 10 11 7 3 6 10 14
输入#4
15 1 4 1 4 1 8 2 8 2 11 2 11 3 11 3 11 4 12 5 12 5 13 8 14 11 15 11 15 12 15 15 13 9 3 8 11 6 5 12 2 4 7 14 1 10
输出#4
44 41 37 29 22 16 12 11 16 20 21 27 35 39 42 49
说明/提示
Sample 1 Explanation:
An optimal schedule for each k is as follows:
- k=0: Perform jobs 1,2,3 on days 1,2,3 respectively. The total cost is (3−1)+(3−2)+(3−3)=3.
- k=1: Perform jobs 1,2,3 on days 2,1,3 respectively. The total cost is (3−2)+(1−1)+(3−3)=1.
- k=2: Perform jobs 1,2,3 on days 1,2,3 respectively. The total cost is (1−1)+(2−1)+(3−3)=1.
- k=3: Perform jobs 1,2,3 on days 1,2,3 respectively. The total cost is (1−1)+(2−1)+(3−2)=2.
Constraints
- 1≤N≤106
- 1≤Li≤i≤Ri≤N
- 1≤L1≤L2≤⋯≤LN≤N
- 1≤R1≤R2≤⋯≤RN≤N
- (P1,P2,…,PN) is a permutation of (1,2,…,N).
- All input values are integers.
样例 1 解释:
对于每个 k,一个最优调度方案如下:
- k=0:在第 1,2,3 天分别执行作业 1,2,3。总代价为 (3−1)+(3−2)+(3−3)=3。
- k=1:在第 2,1,3 天分别执行作业 1,2,3。总代价为 (3−2)+(1−1)+(3−3)=1。
- k=2:在第 1,2,3 天分别执行作业 1,2,3。总代价为 (1−1)+(2−1)+(3−3)=1。
- k=3:在第 1,2,3 天分别执行作业 1,2,3。总代价为 (1−1)+(2−1)+(3−2)=2。
限制条件
- 1≤N≤106
- 1≤Li≤i≤Ri≤N
- 1≤L1≤L2≤⋯≤LN≤N
- 1≤R1≤R2≤⋯≤RN≤N
- (P1,P2,…,PN) 是 (1,2,…,N) 的一个排列。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?