CF963C.Cutting Rectangle

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A rectangle with sides AA and BB is cut into rectangles with cuts parallel to its sides. For example, if pp horizontal and qq vertical cuts were made, (p+1)⋅(q+1)(p + 1) \cdot (q + 1) rectangles were left after the cutting. After the cutting, rectangles were of nn different types. Two rectangles are different if at least one side of one rectangle isn't equal to the corresponding side of the other. Note that the rectangle can't be rotated, this means that rectangles a×ba \times b and b×ab \times a are considered different if a≠ba \neq b.

For each type of rectangles, lengths of the sides of rectangles are given along with the amount of the rectangles of this type that were left after cutting the initial rectangle.

Calculate the amount of pairs (A;B)(A; B) such as the given rectangles could be created by cutting the rectangle with sides of lengths AA and BB. Note that pairs (A;B)(A; B) and (B;A)(B; A) are considered different when A≠BA \neq B.

一个边长为 AA 和 BB 的矩形,通过一系列平行于其边的切割被分割成若干小矩形。例如,若进行了 pp 次水平切割和 qq 次垂直切割,则最终得到 (p+1)⋅(q+1)(p + 1) \cdot (q + 1) 个小矩形。切割完成后,这些小矩形共分为 nn 种不同类型。两个矩形属于不同类型,当且仅当它们至少有一条对应边的长度不相等。注意:矩形不可旋转,即当 a≠ba \neq b 时,a×ba \times b 型矩形与 b×ab \times a 型矩形被视为不同类型。

对于每种类型的小矩形,题目给出其两条边的长度,以及该类型矩形在切割后剩余的数量。

请计算满足条件的边长对 (A;B)(A; B) 的数量,使得给定的所有小矩形恰好可通过切割一个边长为 AA 和 BB 的原始矩形而得到。注意:当 A≠BA \neq B 时,(A;B)(A; B) 与 (B;A)(B; A) 被视为不同的边长对。

输入格式

The first line consists of a single integer nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^{5}) — amount of different types of rectangles left after cutting the initial rectangle.

The next nn lines each consist of three integers wi,hi,ciw_{i}, h_{i}, c_{i} (1≤wi,hi,ci≤1012)(1 \leq w_{i}, h_{i}, c_{i} \leq 10^{12}) — the lengths of the sides of the rectangles of this type and the amount of the rectangles of this type.

It is guaranteed that the rectangles of the different types are different.

第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^{5})—— 初始矩形被切割后剩余的不同类型矩形的种类数。

接下来的 nn 行,每行包含三个整数 wi,hi,ciw_{i}, h_{i}, c_{i}(1≤wi,hi,ci≤10121 \leq w_{i}, h_{i}, c_{i} \leq 10^{12})—— 此类矩形的两条边长及其数量。

保证不同种类的矩形互不相同。

输出格式

Output one integer — the answer to the problem.

输出一个整数——该问题的答案。

输入输出样例

  • 输入#1

    1
    1 1 9

    输出#1

    3
  • 输入#2

    2
    2 3 20
    2 4 40

    输出#2

    6
  • 输入#3

    2
    1 2 5
    2 3 5

    输出#3

    0

说明/提示

In the first sample there are three suitable pairs: (1;9)(1; 9), (3;3)(3; 3) and (9;1)(9; 1).

In the second sample case there are 6 suitable pairs: (2;220)(2; 220), (4;110)(4; 110), (8;55)(8; 55), (10;44)(10; 44), (20;22)(20; 22) and (40;11)(40; 11).

Here the sample of cut for (20;22)(20; 22).

The third sample has no suitable pairs.

第一个样例中有三对满足条件的数:(1;9)(1; 9)、(3;3)(3; 3) 和 (9;1)(9; 1)。

第二个样例中有六对满足条件的数:(2;220)(2; 220)、(4;110)(4; 110)、(8;55)(8; 55)、(10;44)(10; 44)、(20;22)(20; 22) 和 (40;11)(40; 11)。

以下是 (20;22)(20; 22) 的切割示例:

第三个样例中不存在满足条件的数对。

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

首页