#P4125. [WC2012] 记忆中的水杉树

    ID: 3056 远端评测题 3000ms 125MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>计算几何2012线段树WC/CTSC/集训队Special Judge拓扑排序

[WC2012] 记忆中的水杉树

Description

Changzhou Senior High School of Jiangsu is a century-old prestigious school, filled with countless unforgettable memories.

Will remembers that when he was little, before the school's reconstruction, there was a tall metasequoia grove. When the metasequoias shed their leaves, the needles would cover the ground like a blanket, making it romantic and leisurely to walk on. Back then, Will and his classmates liked to use these needles to play a “taking needles” game under the metasequoias.

At the start of the game, everyone lays nn needles flat on the ground. Then, in each round, one player may choose one needle and move it in the horizontal or vertical direction (that is, translate it to infinity) — provided that during the movement it is not blocked by any needle that has not yet been moved away. If a needle’s movement would be blocked in a round, then this move is illegal and not allowed.

After nn rounds, when all needles have been removed, the game ends. Not every needle can be moved at any time. When there are many needles, determining in each round whether a specific needle can be moved in a given direction is troublesome. Now we abstract the ground as a 2D Cartesian plane, the nn needles as nn pairwise disjoint line segments in the plane, labeled from 11 to nn. Will also provides, for each round, the index of the needle he wants to move and the direction. Please help him:

  1. Find in which round the earliest illegal move occurs.
  2. Provide a legal move sequence that completes the game.

Note: When moving segments, merely touching at endpoints does not cause obstruction. See the sample for details.

Input Format

The first line contains a positive integer nn, the number of needles.

The next nn lines each contain 44 integers describing the positions of the needles. On the ii-th of these lines, the integers aia_i, bib_i, cic_i, did_i indicate that the endpoints of the line segment abstracting needle ii are (ai,bi)(a_i, b_i) and (ci,di)(c_i, d_i).

The next nn lines each contain 22 integers describing the moves. On the ii-th of these lines, the integers pip_i, qiq_i indicate that in round ii, the needle to move is pip_i, and the direction is qiq_i. Here qiq_i is an integer between 00 and 33: 00 means move left (the negative xx-axis direction), 11 means move up (the positive yy-axis direction), 22 means move right, and 33 means move down.

The input is guaranteed that:

  • All segments have positive length, no two segments share a point, and there are no vertical or horizontal segments.
  • p1p_1 through pnp_n form a permutation of 11 through nn.
  • There is at least one illegal move in Will’s given sequence.
  • There always exists a sequence of nn legal moves that completes the game.

Output Format

The output contains n+1n+1 lines.

The first line contains an integer between 11 and nn, indicating the earliest round in which an illegal move occurs.

The next nn lines each contain two integers, as in the input format, describing a legal move sequence.

5 
2 5 5 8 
2 1 3 5 
5 2 6 5 
7 0 4 2 
3 1 4 0 
2 0 
3 0 
4 0 
1 2 
5 1 
3 
2 0 
3 0 
4 3 
1 2 
5 1 
4
-1 1 2 3
13 5 9 8
10 10 15 14
10 17 0 20
3 1
2 1
1 1

4 1
2
4 1
3 1
2 1
1 1

Hint

[Sample explanation]

In round 33 of Will’s given plan, moving needle 44 to the left is blocked by needle 55.

[Constraints]

See the table below.

For a test point:

  • If the illegal move detection is correct but the provided plan is wrong, you can get 55 points. The message will be: An invalid move in step.
  • If the illegal move detection is wrong but the provided plan is correct, you can get 55 points. The message will be: Negative error detection!.
  • If both the detection and the plan are correct, you get 1010 points; otherwise, 00 points.

If the program’s output format is incorrect, it will be directly judged as 00 points.

Translated by ChatGPT 5