#P6010. [USACO20JAN] Falling Portals P

[USACO20JAN] Falling Portals P

Description

There are NN worlds (2N2×1052 \leq N \leq 2 \times 10^5), and each world has a portal. Initially, world ii (for 1iN1 \leq i \leq N) is at xx-coordinate ii and yy-coordinate AiA_i (1Ai1091 \leq A_i \leq 10^9). Each world also contains a cow. At time 00, all yy-coordinates are distinct, and then the worlds begin to fall: world ii moves along the negative yy-axis at a speed of ii units per second.

At any time, if two worlds have the same yy-coordinate at some moment (possibly at a non-integer time), their portals will “synchronize”, allowing a cow in one world to choose to instantly teleport to the other world.

For each ii, the cow in world ii wants to go to world QiQ_i (QiiQ_i \neq i). Help each cow compute how much time it takes if she moves in the best possible way.

Each query should be output as a fraction a/ba/b, where aa and bb are coprime positive integers, or 1-1 if it is impossible to reach.

Input Format

The first line contains an integer NN.

The next line contains NN space-separated integers A1,A2,,ANA_1, A_2, \ldots, A_N.

The next line contains NN space-separated integers Q1,Q2,,QNQ_1, Q_2, \ldots, Q_N.

Output Format

Output NN lines. The ii-th line contains the travel time for cow ii.

4
3 5 10 2
3 3 2 1
7/2
7/2
5/1
-1

Hint

Sample Explanation

Consider the answer for the cow originally in world 22. At time 22, worlds 11 and 22 synchronize, so the cow can go to world 11. At time 72\frac{7}{2}, worlds 11 and 33 synchronize, so the cow can go to world 33.

Subtasks

  • Test points 232 \sim 3 satisfy N100N \leq 100.
  • Test points 454 \sim 5 satisfy N2000N \leq 2000.
  • Test points 6146 \sim 14 have no additional constraints.

Translated by ChatGPT 5