CF1690C.Restoring the Duration of Tasks

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Recently, Polycarp completed nn successive tasks.

For each completed task, the time sis_i is known when it was given, no two tasks were given at the same time. Also given is the time fif_i when the task was completed. For each task, there is an unknown value did_i (di>0d_i \gt 0) — duration of task execution.

It is known that the tasks were completed in the order in which they came. Polycarp performed the tasks as follows:

  • As soon as the very first task came, Polycarp immediately began to carry it out.
  • If a new task arrived before Polycarp finished the previous one, he put the new task at the end of the queue.
  • When Polycarp finished executing the next task and the queue was not empty, he immediately took a new task from the head of the queue (if the queue is empty — he just waited for the next task).

Find did_i (duration) of each task.

最近,Polycarp 连续完成了 nn 个任务。

对于每个已完成的任务,已知其被分配的时间 sis_i,且任意两个任务的分配时间均不相同。同时,还已知该任务完成的时间 fif_i。对每个任务,存在一个未知值 did_i(di>0d_i \gt 0)——即该任务的实际执行时长。

已知这些任务是按照它们被分配的顺序依次完成的。Polycarp 执行任务的方式如下:

  • 一旦第一个任务被分配,Polycarp 立即开始执行它;
  • 若在 Polycarp 完成上一个任务之前有新任务到达,则他将该新任务加入队列尾部;
  • 当 Polycarp 完成当前任务后,若队列非空,则他立即从队列头部取出下一个任务开始执行(若队列为空,则他等待下一个任务到达)。

请计算每个任务的执行时长 did_i。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

The descriptions of the input data sets follow.

The first line of each test case contains one integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5).

The second line of each test case contains exactly nn integers s1<s2<⋯<sns_1 \lt s_2 \lt \dots \lt s_n (0≤si≤1090 \le s_i \le 10^9).

The third line of each test case contains exactly nn integers f1<f2<⋯<fnf_1 \lt f_2 \lt \dots \lt f_n (si<fi≤109s_i \lt f_i \le 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。

随后是各测试用例的输入数据描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)。

每个测试用例的第二行包含恰好 nn 个整数 s1<s2<⋯<sns_1 \lt s_2 \lt \dots \lt s_n(0≤si≤1090 \le s_i \le 10^9)。

每个测试用例的第三行包含恰好 nn 个整数 f1<f2<⋯<fnf_1 \lt f_2 \lt \dots \lt f_n(si<fi≤109s_i \lt f_i \le 10^9)。

保证所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each of tt test cases print nn positive integers d1,d2,…,dnd_1, d_2, \dots, d_n — the duration of each task.

对于每个测试用例,输出 nn 个正整数 d1,d2,…,dnd_1, d_2, \dots, d_n —— 即每个任务的持续时间。

输入输出样例

  • 输入#1

    4
    3
    0 3 7
    2 10 11
    2
    10 15
    11 16
    9
    12 16 90 195 1456 1569 3001 5237 19275
    13 199 200 260 9100 10000 10914 91066 5735533
    1
    0
    1000000000

    输出#1

    2 7 1 
    1 1 
    1 183 1 60 7644 900 914 80152 5644467 
    1000000000

说明/提示

First test case:

The queue is empty at the beginning: [][ ]. And that's where the first task comes in. At time 22, Polycarp finishes doing the first task, so the duration of the first task is 22. The queue is empty so Polycarp is just waiting.

At time 33, the second task arrives. And at time 77, the third task arrives, and now the queue looks like this: [7][7].

At the time 1010, Polycarp finishes doing the second task, as a result, the duration of the second task is 77.

And at time 1010, Polycarp immediately starts doing the third task and finishes at time 1111. As a result, the duration of the third task is 11.

An example of the first test case.

第一个测试用例:

队列初始为空:[][ ]。此时第一个任务到达。在时刻 22,Polycarp 完成第一个任务,因此第一个任务的持续时间为 22。此时队列为空,Polycarp 处于等待状态。

在时刻 33,第二个任务到达;在时刻 77,第三个任务到达,此时队列状态为:[7][7]。

在时刻 1010,Polycarp 完成第二个任务,因此第二个任务的持续时间为 77。

在时刻 1010,Polycarp 立即开始处理第三个任务,并于时刻 1111 完成。因此第三个任务的持续时间为 11。

第一个测试用例的示意图。

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

首页