QOJ.ac

QOJ

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

#10367. 开车

統計

你有 $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$ 之间。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.