#P11118. [ROI 2024] 无人机比赛 (Day 2)

[ROI 2024] 无人机比赛 (Day 2)

Background

Translated from ROI 2024 D2T3.

There are nn drones registered to participate in a drone race. The ii-th drone needs tit_i seconds to fly one unit of distance.

The race is held on a straight line with mm gates, numbered from 11 to mm. The ii-th gate is located at distance sis_i from the start of the race.

Due to the limited size of the track, only the first kk drones will participate in the first race, numbered from 11 to kk. The value of kk will be announced by the judges before the race starts, so you need to analyze the race outcome for all kk from 11 to nn.

The race proceeds as follows:

The drones move from point 00 toward the gates, and each drone has a different speed. Each drone has a checkpoint, which is the last gate where it performed a save operation. Initially, every drone’s checkpoint is point 00.

During the race, all drones start moving from their checkpoints, until one or more drones reach a gate (it is possible that different drones reach different gates at the same time). At that moment, among all drones that have reached a gate, choose the drone with the smallest index and perform a save operation for it, setting its checkpoint to the current position. All other drones are immediately teleported back to their checkpoints. Then the race continues.

If a drone performs a save operation at the last gate, numbered mm, then it finishes the race. The drones that have not yet finished will be teleported back to their checkpoints and continue racing. When all drones finish, the race ends.

Problem Description

Teleportation is a very energy-consuming process. To prepare for the race, you need to know how many times in total all drones will teleport before the race ends. Let ckc_k denote the total number of teleports made by all drones when the first kk drones participate in the race. You need to compute c1,c2,,cnc_1, c_2, \dots, c_n.

Input Format

The first line contains two integers nn and mm, representing the number of drones and the number of gates, respectively (2n1500002 \leq n \leq 1500001m1500001 \leq m \leq 150000).

The second line contains nn positive integers t1,t2,,tnt_1, t_2, \dots, t_n, where tit_i is the number of seconds the ii-th drone needs to fly one unit of distance (1ti1091 \leq t_i \leq 10^9).

The third line contains mm positive integers s1,s2,,sms_1, s_2, \dots, s_m, where sis_i is the position of the ii-th gate (1s1<s2<<sm1500001 \leq s_1 < s_2 < \dots < s_m \leq 150000).

Output Format

Output nn integers c1,c2,,cnc_1, c_2, \dots, c_n, as described above.

3 3
1 2 3
1 3 6
0
4
11
3 3
3 2 1
1 3 6
0
5
13
2 5
2 1
1 3 4 6 7
0
6

Hint

Sample 11 explanation:

When k=1k=1, no teleportation is needed, because only one drone participates, and only it keeps saving all the time.

When k=2k=2, the whole race process is shown in the figure below.

When k=3k=3, the whole race process is shown in the figure below.

Special properties table for subtasks:

Subtask Score nn\le mm\le tit_i\le sis_i\le Other special properties
11 55 22 5050 100000100000 100000100000
22 77 5050
33 1313 10001000 55
44 99 100000100000 100000100000 si+1si=s1s_{i+1}-s_i=s_1
55 88 All tit_i are equal
66 1010 100100
77 55 100000100000 22
88 77 m=2m=2 100000100000
99 66 1000010000 100000100000
1010 5000050000
1111 88 100000100000
1212
1313

Translated by ChatGPT 5