QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#10367. 开车

Statistics

你有 $n$ 辆车,分别 $a_1, a_2, \ldots, a_n$ 位置和 $n$ 个加油站,分别在 $b_1, b_2, \ldots ,b_n$ 。每个加油站只能支持一辆车的加油,所以你要把这些车开到不同的加油站加油。一个车从 $x$ 位置开到 $y$ 位置的代价为 $|x-y|$ ,问如何安排车辆,使得代价之和最小。同时你有 $q$ 个操作,每次操作会修改第 $i$ 辆车的位置到 $x$,你要回答每次修改操作之后最优安排方案的总代价。

输入格式

第一行一个正整数 $n$。

接下来一行 $n$ 个整数 $a_1, a_2, \ldots,a_n$。

接下来一行 $n$ 个整数 $b_1, b_2, \ldots ,b_n$。

接下来一行一个正整数 $q$,表示操作的个数。

接下来 $q$ 行,每行有两个整数 $i$ ($1 \le i \le n$) 和 $x$,表示将 $i$ 这辆车开到 $x$ 位置的操作。

输出格式

共 $q+1$ 行,第一行表示一开始的最优代价。

接下来 $q$ 行,第 $i$ 行表示操作 $i$ 之后的最优代价。

样例数据

样例输入

2
1 2
3 4
1
1 3

样例输出

4
2

样例解释

一开始将第一辆车开到位置 $4$,将第二辆车开到位置 $3$,代价为 $|4-1|+|3-2|=4$。

修改后第一辆车的位置变成 $3$,代价为 $|3-3|+|4-2|=2$。

子任务

测试点编号 $n \leq $ $q \leq$
$1$ $1\,000$ $0$
$2$ $1000$
$3$ $10^4$ $10^4$
$4$ $5 \times 10^4$ $0$
$5$ $3 \times 10^4$ $3 \times 10^4$
$6$
$7$ $5 \times 10^4$ $5 \times 10^4$
$8$
$9$
$10$

对于 $100\%$ 的数据,$1 \le n, q \le 5 \times 10^4$,所有的车和加油站的范围一直在 $0$ 到 $10^9$ 之间。

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.