luogu#P4758. [CERC2014] Mountainous landscape

[CERC2014] Mountainous landscape

题目描述

You travel through a scenic landscape consisting mostly of mountains – there are nn landmarks (peaks and valleys) on your path. You pause for breath and wonder: which mountain are you currently seeing on the horizon?

0

Formally: you are given a polygonal chain P1,P2,,PnP_1,P_2,\cdots,P_n in the plane. The xx coordinates of the points are in strictly increasing order. For each segment PiPi+1P_i P_{i+1} of this chain, find the smallest index j>ij > i, for which any point of PjPj+1P_j P_{j+1} is visible from PiPi+1P_i P_{i+1} (lies strictly above the ray Pi Pi+1P_i \ P^{\rightarrow}_{i+1}).

输入格式

The first line of input contains the number of test cases TT. The descriptions of the test cases follow:

The first line of each test case contains an integer n(2n100000)n(2 \le n \le 100 000) – the number of vertices on the chain.

Each of the following nn lines contains integer coordinates xi,yix_i, y_i of the vertex $P_i (0 \le x_1 < x_2 < \cdots < x_n \le 10^9, 0 \le y_i \le 10^9)$.

输出格式

For each test case, output a single line containing n1n-1 space-separated integers. These should be the smallest indices of chain segments visible to the right, or 00 when no such segment exists.

题目大意

  • 给定平面内一个由点依次连接起来形成的折线 P1,P2,,PnP_1,P_2,\cdots,P_n,保证 xx 坐标递增。
  • 对于折线上的所有线段,找到最小的 j>ij>i,使得存在一个在 PjPj+1P_jP_{j+1} 上的点可以被 PiPi+1P_iP_{i+1} 上的任何一个点看到,也就是严格在射线 PiPi+1P_iP_{i+1} 上方。若没有,输出 00.
  • 多组数据。

2n1052\le n\le 10^5,坐标均在 10910^9 以内。

2
8
0 0
3 7
6 2
9 4
11 2
13 3
17 13
20 7
7
0 2
1 2
3 1
4 0
5 2
6 1
7 3
0 3 6 5 6 0 0
6 4 4 0 6 0