CF1439E.Cheat and Win

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Let's consider a (109+1)×(109+1)(10^9+1) \times (10^9+1) field. The rows are numbered with integers from 00 to 10910^9 and the columns are numbered with integers from 00 to 10910^9. Let's define as (x,y)(x, y) the cell located in the xx-th row and yy-th column.

Let's call a cell (x,y)(x, y) good if x&y=0x \& y = 0, there &\& is the bitwise and operation.

Let's build a graph where vertices will be all good cells of the field and we will make an edge between all pairs of adjacent by side good cells. It can be proved that this graph will be a tree — connected graph without cycles. Let's hang this tree on vertex (0,0)(0, 0), so we will have a rooted tree with root (0,0)(0, 0).

Two players will play the game. Initially, some good cells are black and others are white. Each player on his turn chooses a black good cell and a subset of its ancestors (possibly empty) and inverts their colors (from white to black and vice versa). The player who can't move (because all good cells are white) loses. It can be proved that the game is always finite.

Initially, all cells are white. You are given mm pairs of cells. For each pair color all cells in a simple path between them as black. Note that we do not invert their colors, we paint them black.

Sohrab and Mashtali are going to play this game. Sohrab is the first player and Mashtali is the second.

Mashtali wants to win and decided to cheat. He can make the following operation multiple times before the game starts: choose a cell and invert colors of all vertices on the path between it and the root of the tree.

Mammad who was watching them wondered: "what is the minimum number of operations Mashtali should do to have a winning strategy?".

Find the answer to this question for the initial painting of the tree. It can be proved that at least one possible way to cheat always exists.

我们考虑一个 (109+1)×(109+1)(10^9+1) \times (10^9+1) 的方格。行编号为从 00 到 10910^9 的整数,列编号也为从 00 到 10910^9 的整数。记 (x,y)(x, y) 为位于第 xx 行、第 yy 列的格子。

若满足 x&y=0x \& y = 0,则称格子 (x,y)(x, y) 是好格子,其中 &\& 表示按位与运算。

我们构造一个图:其顶点集为所有好格子;对任意两个边相邻(即共享一条边)的好格子之间连一条无向边。可以证明,该图是一棵树——即连通且无环的图。我们将这棵树以顶点 (0,0)(0, 0) 为根悬挂起来,从而得到一棵以 (0,0)(0, 0) 为根的有根树。

两名玩家将进行如下博弈:初始时,某些好格子为黑色,其余为白色。每一轮中,当前玩家选择一个黑色的好格子,并选择其任意一个祖先集合(可以为空集),然后将这些格子的颜色全部翻转(白变黑,黑变白)。无法操作者(即所有好格子均为白色时)判负。可以证明,该博弈总是有限的。

初始时,所有格子均为白色。现给出 mm 对格子。对每一对格子,将它们之间简单路径上的所有格子染成黑色。(注意:此处不是翻转颜色,而是直接涂黑。)

Sohrab 和 Mashtali 将进行这场博弈,Sohrab 先手,Mashtali 后手。

Mashtali 想获胜,因此决定作弊。他在游戏开始前可执行以下操作任意多次:任选一个格子,并将该格子到树根(即 (0,0)(0, 0))路径上所有顶点的颜色全部翻转。

在一旁观察的 Mammad 心生疑惑:“Mashtali 至少需要执行多少次上述作弊操作,才能保证自己拥有必胜策略?”

请针对给定的初始染色方案,回答这一问题。可以证明,总存在至少一种可行的作弊方式。

输入格式

The first line contains one integer mm (1≤m≤1051 \leq m \leq 10^5).

Each of the next mm lines contains four integers x1x_{1}, y1y_{1}, x2x_{2}, y2y_{2} (0≤xi,yi≤1090 \leq x_i, y_i \leq 10^9, xi&yi=0x_i \& y_i = 0). You should color all cells on the path between vertices (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) as black.

第一行包含一个整数 mm(1≤m≤1051 \leq m \leq 10^5)。

接下来的 mm 行中,每行包含四个整数 x1x_{1}、y1y_{1}、x2x_{2}、y2y_{2}(0≤xi,yi≤1090 \leq x_i, y_i \leq 10^9,且 xi&yi=0x_i \& y_i = 0)。你需要将顶点 (x1,y1)(x_1, y_1) 与 (x2,y2)(x_2, y_2) 之间路径上的所有格子涂成黑色。

输出格式

Print a single integer — the minimum number of cheating operations the second player can do.

输出一个整数——第二位玩家所需的最少作弊操作次数。

输入输出样例

  • 输入#1

    1
    7 0 0 7

    输出#1

    1
  • 输入#2

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

    输出#2

    3
  • 输入#3

    2
    0 1 0 8
    1 0 8 0

    输出#3

    0

说明/提示

In the first test, you can make one cheating operation with the root of the tree. After that, the second player can win because he can use a symmetric strategy.

In the second test, you can make cheating operations with cells (0,2),(0,0),(3,4)(0, 2), (0, 0), (3, 4).

In the third test, the second player already has the winning strategy and doesn't need to make any cheating operations.

在第一个测试中,你可以对树的根节点执行一次作弊操作。此后,第二名玩家可以获胜,因为他可以采用对称策略。

在第二个测试中,你可以对格子 (0,2),(0,0),(3,4)(0, 2), (0, 0), (3, 4) 执行作弊操作。

在第三个测试中,第二名玩家已拥有必胜策略,无需执行任何作弊操作。

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

首页