Under construction

Still being built. Things may change

Immunization Operation

Memory limit1024 MB

Summary
Given each vaccine's pickup and delivery points and a list of east or west moves, count the vaccinations completed during each move.
Level

Medium6 of 10

Topics
Sorting, Simulation, Binary search, Array
Solved
No attempts yet

Problem

Making every vaccine available to the entire world population is a complicated problem in many respects. Ñambi is leading the effort to optimize delivery. To reduce access barriers as much as possible, she is designing robots that deliver and apply vaccines directly in patients' homes.

In the current iteration, the robot works on a single street that runs from west to east. The robot accepts a single command, 'move xx meters'. If xx is positive, the robot moves xx meters east. If xx is negative, the robot moves −x-x meters west.

At the start of the day, the robot is loaded with information about all immunizations it must provide that day. Each immunization has a pickup location, where the vaccine is currently kept, and a delivery location, where the patient lives. Each vaccine is custom-made for one patient. A delivery location is never the same as its pickup location. The robot must pick up a vaccine before it delivers it.

The robot picks up a vaccine the first time it passes through that vaccine's pickup location. It delivers a vaccine as soon as it passes through the delivery location, provided the vaccine has already been picked up. Ñambi wants to track how many vaccinations happen after each movement command. A vaccination happens when a vaccine is delivered. A vaccine may be picked up during any earlier command, or during the same command as its delivery, as long as the pickup happens before the delivery.

The figure below shows one possible scenario (Sample Case #1). The smiley face is the robot's starting position, and the long black line is the street. Marks above the line are pickup locations, and marks below are delivery locations. The arrows below show the moves in order from top to bottom, labeled with the number of deliveries completed during each move.

What happens during each move, in order:

  • Move 1. The robot picks up vaccines 5 and 1, delivers vaccine 1, and picks up vaccine 3 just as the move finishes. The robot passes the delivery location of vaccine 3 before picking it up, so it cannot deliver it.
  • Move 2. The robot passes the delivery locations of vaccines 1 and 4. Vaccine 1 is already delivered and vaccine 4 has not been picked up, so no vaccination finishes.
  • Move 3. The robot delivers vaccine 3.
  • Move 4. The robot picks up vaccine 2, delivers vaccine 5, and picks up vaccine 4.

Vaccines 2 and 4 are picked up but not delivered. The delivery location of vaccine 2 is never reached, and the delivery location of vaccine 4 is not reached after the vaccine is picked up.

Given the list of immunizations and the list of move commands, the robot executes the commands in order. Compute how many vaccinations are completed after each command.

Input

The first line contains the number of test cases, TT. Each test case consists of four lines.

The first line of a test case contains two integers VV and MM, the number of vaccinations and the number of move commands.

The second line contains VV integers P1,P2,…,PVP_1, P_2, \dots, P_V. The ii-th vaccine must be picked up exactly PiP_i meters east of the robot's initial location. Several vaccines can share the same pickup location.

The third line contains VV integers D1,D2,…,DVD_1, D_2, \dots, D_V. The ii-th vaccine must be delivered exactly DiD_i meters east of the robot's initial location. Several vaccines can share the same delivery location.

The fourth line contains MM integers X1,X2,…,XMX_1, X_2, \dots, X_M. The absolute value of XjX_j is the number of meters the robot moves for the jj-th command. The move is east if XjX_j is positive and west if it is negative. Vaccinations can happen in an order different from the input numbering, but movement commands happen in the given order.

Output

For each test case, output one line containing Case #x: y1 y2 ... yM, where xx is the test case number (starting from 1) and yjy_j is the number of vaccinations completed during the jj-th movement command.

Limits

  • 1≤T≤1001 \le T \le 100.
  • 1≤Pi≤1091 \le P_i \le 10^9, for all ii.
  • 1≤Di≤1091 \le D_i \le 10^9, for all ii.
  • Pi≠DiP_i \neq D_i, for all ii.
  • −109≤Xj≤109-10^9 \le X_j \le 10^9, for all jj.
  • Xj≠0X_j \ne 0, for all jj.

Hints

Sample Case #1 is the one explained and illustrated in the problem statement.

In Sample Case #2 and Sample Case #3, a vaccine can be picked up and delivered in the same move only if its pickup place is visited first. A pickup and delivery can also happen exactly as a move ends.

In Sample Case #4, the robot moves 987654321 meters west five times, then 987654321 meters east four times, then 987654323 meters east. The only pickup and delivery both happen during the final move. The commands can be very large, so the robot can end up very far from its starting position, either west or east.

Examples1

  1. Example 1

    Input
    4
    5 4
    121 312 271 422 75
    199 464 160 234 368
    271 -109 -70 371
    2 2
    1 3
    4 4
    4 -1
    2 2
    1 4
    4 3
    4 -1
    1 10
    1
    2
    -987654321 -987654321 -987654321 -987654321 -987654321 987654321 987654321 987654321 987654321 987654323
    
    Expected output
    Case #1: 1 0 1 1
    Case #2: 2 0
    Case #3: 1 1
    Case #4: 0 0 0 0 0 0 0 0 0 1