QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 1024 MB 總分: 100

#3493. 滑雪缆车

统计

去年冬天,一场雪崩摧毁了 Valen 滑雪胜地的所有缆车。现在的计划不是按原样重建,而是以一种更优化的方式进行,而你负责这项工作。

Picture by SkiHoodoo from Wikimedia Commons, cc by-sa

旧缆车系统中唯一保留下来的是 $n$ 个位于平面上整数坐标处的塔架。你希望在这些塔架之间以线段的形式架设缆车。这些线段必须满足以下约束:

  1. 线段只能连接满足 $|y_1 - y_2| = 1$ 的塔架 $(x_1, y_1)$ 和 $(x_2, y_2)$。
  2. 塔架分为两种类型:单向塔架和双向塔架。单向塔架最多只能连接到另一个塔架,双向塔架最多可以连接到两个其他塔架。然而,如果一个双向塔架 $i$ 连接了两个其他塔架,那么它们必须位于 $i$ 在 $y$ 方向上的两侧。换句话说,连接到 $i$ 的两个塔架必须具有不同的 $y$ 坐标。
  3. 两条线段不得相交(连接到同一个双向塔架的两条线段可以在其端点处接触)。

在这些约束条件下,你可以架设的缆车(线段)的最大数量是多少?

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 10^5$)。接下来的 $n$ 行,每行包含三个整数 $x, y$ 和 $a$,分别表示塔架的坐标和类型($0 \le x, y \le 10^5$;$a = 1$ 表示单向塔架,$a = 2$ 表示双向塔架)。所有塔架的坐标均不相同。

输出格式

输出可以架设的缆车线段的最大数量。

样例

输入格式 1

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

输出格式 1

4

输入格式 2

4
0 0 1
100000 1 1
0 99999 1
100000 100000 1

输出格式 2

2

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.