CF1195F.Geometers Anonymous Club

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Denis holds a Geometers Anonymous Club meeting in SIS. He has prepared nn convex polygons numbered from 11 to nn for the club. He plans to offer members of the club to calculate Minkowski sums of these polygons. More precisely, he plans to give qq tasks, the ii-th of them asks to calculate the sum of Minkowski of polygons with indices from lil_i to rir_i inclusive.

The sum of Minkowski of two sets AA and BB is the set C=a+b:a∈A,b∈BC = {a + b : a \in A, b \in B}. It can be proven that if AA and BB are convex polygons then CC will also be a convex polygon.

Sum of two convex polygons

To calculate the sum of Minkowski of pp polygons (p>2p \gt 2), you need to calculate the sum of Minkowski of the first p−1p - 1 polygons, and then calculate the sum of Minkowski of the resulting polygon and the pp-th polygon.

For the convenience of checking answers, Denis has decided to prepare and calculate the number of vertices in the sum of Minkowski for each task he prepared. Help him to do it.

丹尼斯在SIS举办了一场“几何学家匿名俱乐部”会议。他为俱乐部准备了 nn 个凸多边形,编号从 11 到 nn。他计划让俱乐部成员计算这些多边形的闵可夫斯基(Minkowski)和。更准确地说,他准备了 qq 个任务,其中第 ii 个任务要求计算编号从 lil_i 到 rir_i(含端点)的所有多边形的闵可夫斯基和。

集合 AA 与 BB 的闵可夫斯基和定义为集合 C={a+b:a∈A, b∈B}C = \{a + b : a \in A,\, b \in B\}。可以证明:若 AA 和 BB 均为凸多边形,则 CC 也必为凸多边形。

两个凸多边形的和

对于 pp 个凸多边形(p>2p > 2)的闵可夫斯基和,需先计算前 p−1p-1 个多边形的闵可夫斯基和,再将所得多边形与第 pp 个多边形作闵可夫斯基和。

为便于核对答案,丹尼斯决定预先计算并记录每个任务所对应闵可夫斯基和的顶点数量。请帮助他完成这一工作。

输入格式

The first line of the input contains one integer nn — the number of convex polygons Denis prepared (1≤n≤100 0001 \le n \le 100\,000).

Then nn convex polygons follow. The description of the ii-th polygon starts with one integer kik_i — the number of vertices in the ii-th polygon (3≤ki3 \le k_i). The next kik_i lines contain two integers xijx_{ij}, yijy_{ij} each — coordinates of vertices of the ii-th polygon in counterclockwise order (∣xij∣,∣yij∣≤109|x_{ij}|, |y_{ij}| \le 10 ^ 9).

It is guaranteed, that there are no three consecutive vertices lying on the same line. The total number of vertices over all polygons does not exceed 300 000300\,000.

The following line contains one integer qq — the number of tasks (1≤q≤100 0001 \le q \le 100\,000). The next qq lines contain descriptions of tasks. Description of the ii-th task contains two integers lil_i and rir_i (1≤li≤ri≤n1 \le l_i \le r_i \le n).

输入的第一行包含一个整数 nn —— Denis 准备的凸多边形的数量(1≤n≤100 0001 \le n \le 100\,000)。

接下来是 nn 个凸多边形。第 ii 个多边形的描述以一个整数 kik_i 开始 —— 表示该多边形的顶点数量(3≤ki3 \le k_i)。随后的 kik_i 行每行包含两个整数 xijx_{ij}、yijy_{ij} —— 表示第 ii 个多边形各顶点的坐标,按逆时针顺序给出(∣xij∣,∣yij∣≤109|x_{ij}|, |y_{ij}| \le 10 ^ 9)。

保证任意三个连续顶点不共线。所有多边形的顶点总数不超过 300 000300\,000。

接下来一行包含一个整数 qq —— 查询任务的数量(1≤q≤100 0001 \le q \le 100\,000)。随后的 qq 行每行描述一个查询任务,第 ii 个任务包含两个整数 lil_i 和 rir_i(1≤li≤ri≤n1 \le l_i \le r_i \le n)。

输出格式

For each task print a single integer — the number of vertices in the sum of Minkowski of polygons with indices from lil_i to rir_i.

对于每个任务,输出一个整数——即索引从 lil_i 到 rir_i 的多边形的闵可夫斯基和的顶点数。

输入输出样例

  • 输入#1

    3
    3
    0 0
    1 0
    0 1
    4
    1 1
    1 2
    0 2
    0 1
    3
    2 2
    1 2
    2 1
    3
    1 2
    2 3
    1 3

    输出#1

    5
    5
    6

说明/提示

Description of the example:

First, second and third polygons from the example

Minkowski sums of the first and second, the second and third and all polygons correspondingly

示例说明:

示例中的第一个、第二个和第三个多边形

第一个与第二个、第二个与第三个、以及所有三个多边形分别对应的闵可夫斯基和

输入解题思路,AI测评打分。不知道怎么写?

首页