题面
传送门:LA-4730
题目大意:
There were N cities in an ancient kingdom. In the beginning of the kingdom, all cities were isolated. Kings ordered their subjects to construct roads connecting cities. A lot of roads were built with time. Every road was always constructed along the line segment between two cities. All cities are partitioned into disjoint components of cities by road-connectivity. A connected component of cities was called a state. A state consists of cities and roads connecting them.
A historical record tells a time sequence of road constructions in order. A road connecting two citiesA and B doesn’t intersect with other roads at a point except forA and B. Before construction,A and B may have belonged to the same state or different states. After construction,A and B would belong to a same state, i.e., two states would merge into a state if needed.
Prof. Kim, a historian, is concerned about the following question: How many states does a horizontal line (corresponding to the latitude of a specific place) pass by at a moment of the past? The figure below shows an example of a configuration of roads at some moment. A circle represents a city and a line segment represents a road between two cities. There are 3 states. A line with y = 4.5 passes by two states with total 8 cities and a line with y = 6.5 passes by one state with 5 cities.
(逃
正经:
平面上有n个城市,初始时城市之间没有任何双向道路相连。你的任务是一次执行以下指令。
road A B:在城市A和B之间连一条双向道路,保证这条道路不和其他道路在非端点处相交。
line C:询问一条Y=C的水平线和多少个州相交,以及这些州一共包含多少座城市。
思路
看到包含多少城市想到并查集。这里如果单个枚举的话很费时间会T飞
我们就用线段树来维护区间内的城市数量和州的数量。
发现其实这题与x轴上的大小值没有任何关系。
只要考虑y轴坐标的上下最值即可
注意分类讨论。
以及并查集的时候别忘记 路径压缩
线段树update别写炸
就A了
代码
3617啊珂怕
1 |
|