AT_agc077_f.Two Types of Tasks Editorial

入门

通过率:0%

时间限制:5.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

There are NN jobs numbered 11 through NN, and you want to complete them over NN days. You perform exactly one job per day.

Job ii can be performed on any day from day LiL_i through day RiR_i. Here, the following conditions are guaranteed to hold for LiL_i and RiR_i:

  • 1LiiRiN1 \leq L_i \leq i \leq R_i \leq N
  • 1L1L2LNN1 \leq L_1 \leq L_2 \leq \cdots \leq L_N \leq N
  • 1R1R2RNN1 \leq R_1 \leq R_2 \leq \cdots \leq R_N \leq N

Particularly, from the first condition, it follows that it is possible to complete all NN jobs over NN 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 ii is performed on day xix_i. If job ii is of type L, the cost is defined as xiLix_i-L_i; if it is of type R, the cost is defined as RixiR_i-x_i.

From now on, there will be NN queries that change the type of a job to L. In the ii-th query, the type of job PiP_i is changed to L.

For each k=0,1,,Nk=0,1,\ldots,N, solve the following problem:

  • Consider the state after processing the first kk queries. Find the minimum possible total cost of all NN jobs.

NN 个编号为 11NN 的任务,你需要在 NN 天内完成它们。每天恰好执行一个任务。

任务 ii 可以在第 LiL_i 天至第 RiR_i 天之间的任意一天执行。其中,LiL_iRiR_i 满足以下条件:

  • 1LiiRiN1 \leq L_i \leq i \leq R_i \leq N
  • 1L1L2LNN1 \leq L_1 \leq L_2 \leq \cdots \leq L_N \leq N
  • 1R1R2RNN1 \leq R_1 \leq R_2 \leq \cdots \leq R_N \leq N

特别地,由第一个条件可知,一定存在一种方案可在 NN 天内完成全部 NN 个任务。

此外,每个任务的类型为 LR。初始时,所有任务的类型均为 R

执行任务的成本定义如下:

  • 假设任务 ii 在第 xix_i 天执行。若任务 ii 的类型为 L,则其成本为 xiLix_i-L_i;若为 R,则其成本为 RixiR_i-x_i

接下来将进行 NN 次查询,每次将某个任务的类型更改为 L。在第 ii 次查询中,任务 PiP_i 的类型被更改为 L

对每个 k=0,1,,Nk=0,1,\ldots,N,求解以下问题:

  • 考虑处理完前 kk 次查询后的状态,求所有 NN 个任务的最小可能总成本。

输入格式

The input is given from Standard Input in the following format:

NN L1L_1 R1R_1 L2L_2 R2R_2 \vdots LNL_N RNR_N P1P_1 P2P_2 \ldots PNP_N

输入从标准输入中按以下格式给出:

NN L1L_1 R1R_1 L2L_2 R2R_2 \vdots LNL_N RNR_N P1P_1 P2P_2 \ldots PNP_N

输出格式

For each k=0,1,2,,Nk=0,1,2,\ldots,N, output the answer in this order, separated by spaces.

对于每个 k=0,1,2,,Nk=0,1,2,\ldots,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 kk is as follows:

  • k=0k=0: Perform jobs 1,2,31,2,3 on days 1,2,31,2,3 respectively. The total cost is (31)+(32)+(33)=3(3-1)+(3-2)+(3-3)=3.
  • k=1k=1: Perform jobs 1,2,31,2,3 on days 2,1,32,1,3 respectively. The total cost is (32)+(11)+(33)=1(3-2)+(1-1)+(3-3)=1.
  • k=2k=2: Perform jobs 1,2,31,2,3 on days 1,2,31,2,3 respectively. The total cost is (11)+(21)+(33)=1(1-1)+(2-1)+(3-3)=1.
  • k=3k=3: Perform jobs 1,2,31,2,3 on days 1,2,31,2,3 respectively. The total cost is (11)+(21)+(32)=2(1-1)+(2-1)+(3-2)=2.

Constraints

  • 1N1061 \leq N \leq 10^6
  • 1LiiRiN1 \leq L_i \leq i \leq R_i \leq N
  • 1L1L2LNN1 \leq L_1 \leq L_2 \leq \cdots \leq L_N \leq N
  • 1R1R2RNN1 \leq R_1 \leq R_2 \leq \cdots \leq R_N \leq N
  • (P1,P2,,PN)(P_1,P_2,\ldots,P_N) is a permutation of (1,2,,N)(1,2,\ldots,N).
  • All input values are integers.

样例 1 解释:
对于每个 kk,一个最优调度方案如下:

  • k=0k=0:在第 1,2,31,2,3 天分别执行作业 1,2,31,2,3。总代价为 (31)+(32)+(33)=3(3-1)+(3-2)+(3-3)=3
  • k=1k=1:在第 2,1,32,1,3 天分别执行作业 1,2,31,2,3。总代价为 (32)+(11)+(33)=1(3-2)+(1-1)+(3-3)=1
  • k=2k=2:在第 1,2,31,2,3 天分别执行作业 1,2,31,2,3。总代价为 (11)+(21)+(33)=1(1-1)+(2-1)+(3-3)=1
  • k=3k=3:在第 1,2,31,2,3 天分别执行作业 1,2,31,2,3。总代价为 (11)+(21)+(32)=2(1-1)+(2-1)+(3-2)=2

限制条件

  • 1N1061 \leq N \leq 10^6
  • 1LiiRiN1 \leq L_i \leq i \leq R_i \leq N
  • 1L1L2LNN1 \leq L_1 \leq L_2 \leq \cdots \leq L_N \leq N
  • 1R1R2RNN1 \leq R_1 \leq R_2 \leq \cdots \leq R_N \leq N
  • (P1,P2,,PN)(P_1,P_2,\ldots,P_N)(1,2,,N)(1,2,\ldots,N) 的一个排列。
  • 所有输入值均为整数。

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

首页