第 77 场 AtCoder Grand Contest
F
两种类型的任务
Two Types of Tasks
AtCoder
未评级
原题
← E→

两种类型的任务AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

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

有 $N$ 个编号为 $1$ 至 $N$ 的任务,你希望在 $N$ 天内完成它们。每天恰好完成一个任务。AI (CI翻译)

Job $i$ can be performed on any day from day $L_i$ through day $R_i$. Here, the following conditions are guaranteed to hold for $L_i$ and $R_i$:

任务 $i$ 可以在第 $L_i$ 天至第 $R_i$ 天中的任意一天完成。保证 $L_i$ 和 $R_i$ 满足以下条件:AI (CI翻译)

  • $1 \leq L_i \leq i \leq R_i \leq N$
  • $1 \leq L_1 \leq L_2 \leq \cdots \leq L_N \leq N$
  • $1 \leq R_1 \leq R_2 \leq \cdots \leq R_N \leq N$
  • $1 \leq L_i \leq i \leq R_i \leq N$
  • $1 \leq L_1 \leq L_2 \leq \cdots \leq L_N \leq N$
  • $1 \leq R_1 \leq R_2 \leq \cdots \leq R_N \leq N$
AI (CI翻译)

Particularly, from the first condition, it follows that it is possible to complete all $N$ jobs over $N$ days.

特别地,由第一个条件可知,可以在 $N$ 天内完成全部 $N$ 个任务。AI (CI翻译)

Furthermore, each job has a type of L or R. Initially, all jobs are of type R.

此外,每个任务的类型为 L 或 R。初始时,所有任务的类型均为 R。AI (CI翻译)

The cost of performing a job is defined as follows:

完成一个任务的代价定义如下:AI (CI翻译)

  • Suppose job $i$ is performed on day $x_i$. If job $i$ is of type L, the cost is defined as $x_i-L_i$; if it is of type R, the cost is defined as $R_i-x_i$.
  • 假设任务 $i$ 在第 $x_i$ 天完成。如果任务 $i$ 的类型为 L,则其代价为 $x_i-L_i$;如果类型为 R,则其代价为 $R_i-x_i$。
AI (CI翻译)

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 $P_i$ is changed to L.

接下来会有 $N$ 次查询,将某个任务的类型修改为 L。第 $i$ 次查询中,任务 $P_i$ 的类型会被修改为 L。AI (CI翻译)

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

对于每个 $k=0,1,\ldots,N$,解决以下问题:AI (CI翻译)

  • Consider the state after processing the first $k$ queries. Find the minimum possible total cost of all $N$ jobs.
  • 考虑处理完前 $k$ 次查询后的状态。求完成全部 $N$ 个任务所需的最小总代价。
AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1 \leq N \leq 10^6$
  • $1 \leq L_i \leq i \leq R_i \leq N$
  • $1 \leq L_1 \leq L_2 \leq \cdots \leq L_N \leq N$
  • $1 \leq R_1 \leq R_2 \leq \cdots \leq R_N \leq N$
  • $(P_1,P_2,\ldots,P_N)$ is a permutation of $(1,2,\ldots,N)$.
  • All input values are integers.
  • $1 \leq N \leq 10^6$
  • $1 \leq L_i \leq i \leq R_i \leq N$
  • $1 \leq L_1 \leq L_2 \leq \cdots \leq L_N \leq N$
  • $1 \leq R_1 \leq R_2 \leq \cdots \leq R_N \leq N$
  • $(P_1,P_2,\ldots,P_N)$ 是 $(1,2,\ldots,N)$ 的一个排列。
  • 所有输入值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

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

输入从标准输入给出,格式如下:AI (CI翻译)

N
L_1 R_1
L_2 R_2
\vdots
L_N R_N
P_1 P_2 \ldots P_N

N
L_1 R_1
L_2 R_2
\vdots
L_N R_N
P_1 P_2 \ldots P_N
AI (CI翻译)

Output

输出格式

AI (CI翻译)

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

按顺序输出每个 $k=0,1,2,\ldots,N$ 对应的答案,并用空格分隔。AI (CI翻译)

样例

Input #1
3
1 3
1 3
2 3
2 1 3
Output #1
3 1 1 2
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$.
Input #2
4
1 4
2 4
3 4
4 4
1 2 3 4
Output #2
6 3 1 0 0
Input #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
Output #3
17 13 10 11 7 3 6 10 14
Input #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
Output #4
44 41 37 29 22 16 12 11 16 20 21 27 35 39 42 49
题目信息
题号
agc077_f
时间限制
5 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。