311395: CF1980F1. Field Division (easy version)

Memory Limit:256 MB Time Limit:3 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F1. Field Division (easy version)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

This is an easy version of the problem; it differs from the hard version only by the question. The easy version only needs you to print whether some values are non-zero or not. The hard version needs you to print the exact values.

Alice and Bob are dividing the field. The field is a rectangle of size $n \times m$ ($2 \le n, m \le 10^9$), the rows are numbered from $1$ to $n$ from top to bottom, and the columns are numbered from $1$ to $m$ from left to right. The cell at the intersection of row $r$ and column $c$ is denoted as ($r, c$).

Bob has $k$ ($2 \le k \le 2 \cdot 10^5$) fountains, all of them are located in different cells of the field. Alice is responsible for dividing the field, but she must meet several conditions:

  • To divide the field, Alice will start her path in any free (without a fountain) cell on the left or top side of the field and will move, each time moving to the adjacent cell down or right. Her path will end on the right or bottom side of the field.
  • Alice's path will divide the field into two parts — one part will belong to Alice (this part includes the cells of her path), the other part — to Bob.
  • Alice will own the part that includes the cell ($n, 1$).
  • Bob will own the part that includes the cell ($1, m$).

Alice wants to divide the field in such a way as to get as many cells as possible.

Bob wants to keep ownership of all the fountains, but he can give one of them to Alice. First, output the integer $\alpha$ — the maximum possible size of Alice's plot, if Bob does not give her any fountain (i.e., all fountains will remain on Bob's plot). Then output $k$ non-negative integers $a_1, a_2, \dots, a_k$, where:

  • $a_i=0$, if after Bob gives Alice the $i$-th fountain, the maximum possible size of Alice's plot does not increase (i.e., remains equal to $\alpha$);
  • $a_i=1$, if after Bob gives Alice the $i$-th fountain, the maximum possible size of Alice's plot increases (i.e., becomes greater than $\alpha$).
Input

The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.

The first line of each test case contains three integers $n$, $m$, and $k$ ($2 \le n, m \le 10^9$, $2 \le k \le 2 \cdot 10^5$) — the field sizes and the number of fountains, respectively.

Then follow $k$ lines, each containing two numbers $r_i$ and $c_i$ ($1 \le r_i \le n$, $1 \le c_i \le m$) — the coordinates of the cell with the $i$-th fountain. It is guaranteed that all cells are distinct and none of them is ($n, 1$).

It is guaranteed that the sum of $k$ over all test cases does not exceed $2 \cdot 10^5$.

Output

For each test case, first output $\alpha$ — the maximum size of the plot that can belong to Alice if Bob does not give her any of the fountains. Then output $k$ non-negative integers $a_1, a_2, \dots, a_k$, where:

  • $a_i=0$, if after Bob gives Alice the $i$-th fountain, the maximum possible size of Alice's plot does not increase compared to the case when all $k$ fountains belong to Bob;
  • $a_i=1$, if after Bob gives Alice the $i$-th fountain, the maximum possible size of Alice's plot increases compared to the case when all $k$ fountains belong to Bob.

If you output any other positive number instead of $1$ that fits into a 64-bit signed integer type, it will also be recognized as $1$. Thus, a solution to the hard version of this problem will also pass the tests for the easy version.

ExampleInput
5
2 2 3
1 1
1 2
2 2
5 5 4
1 2
2 2
3 4
4 3
2 5 9
1 2
1 5
1 1
2 2
2 4
2 5
1 4
2 3
1 3
6 4 4
6 2
1 3
1 4
1 2
3 4 5
2 1
3 2
1 4
1 3
2 4
Output
1
1 0 1 
11
0 1 0 1 
1
0 0 1 1 0 0 0 0 0 
6
1 0 0 0 
1
1 1 0 0 0 
Note

Below are the images for the second example:

The indices of the fountains are labeled in green. The cells belonging to Alice are marked in blue.

Note that if Bob gives Alice fountain $1$ or fountain $3$, then that fountain cannot be on Alice's plot.

Output

题目大意:

这是一个关于划分田地的问题的简单版本,与困难版本的区别仅在于问题的要求。简单版本只需打印某些值是否非零。困难版本需要打印确切的值。

爱丽丝和鲍勃正在划分一个矩形田地,其大小为 $ n \times m $ ($ 2 \le n, m \le 10^9 $),行从上到下编号为 1 到 $ n $,列从左到右编号为 1 到 $ m $。行 $ r $ 和列 $ c $ 交叉的单元格表示为 $ (r, c) $。

鲍勃有 $ k $ ($ 2 \le k \le 2 \cdot 10^5 $)个喷泉,它们都位于田地中的不同单元格。爱丽丝负责划分田地,但她必须满足几个条件:

- 为了划分田地,爱丽丝将从田地的左侧或顶部任意一个没有喷泉的单元格开始她的路径,并且每次向下或向右移动到相邻的单元格。她的路径将在田地的右侧或底部结束。
- 爱丽丝的路径将田地划分为两部分——一部分属于爱丽丝(包括她路径上的单元格),另一部分属于鲍勃。
- 爱丽丝将拥有包括单元格 $ (n, 1) $ 的部分。
- 鲍勃将拥有包括单元格 $ (1, m) $ 的部分。

爱丽丝希望以这种方式划分田地,以获得尽可能多的单元格。

鲍勃希望保留所有喷泉的所有权,但他可以给爱丽丝一个。首先输出整数 $ \alpha $ —— 如果鲍勃不给爱丽丝任何喷泉,爱丽丝的地块可以达到的最大可能大小(即,所有喷泉都留在鲍勃的地块上)。然后输出 $ k $ 个非负整数 $ a_1, a_2, \dots, a_k $,其中:

- 如果鲍勃给爱丽丝第 $ i $ 个喷泉,爱丽丝的地块的最大可能大小没有增加(即,保持等于 $ \alpha $),则 $ a_i = 0 $;
- 如果鲍勃给爱丽丝第 $ i $ 个喷泉,爱丽丝的地块的最大可能大小增加了(即,变得大于 $ \alpha $),则 $ a_i = 1 $。

输入输出数据格式:

输入:
- 第一行包含一个整数 $ t $ ($ 1 \le t \le 10^4 $)——测试用例的数量。
- 每个测试用例的第一行包含三个整数 $ n $、$ m $ 和 $ k $ ($ 2 \le n, m \le 10^9 $,$ 2 \le k \le 2 \cdot 10^5 $)——田地的大小和喷泉的数量。
- 接下来 $ k $ 行,每行包含两个数字 $ r_i $ 和 $ c_i $ ($ 1 \le r_i \le n $,$ 1 \le c_i \le m $)——第 $ i $ 个喷泉所在单元格的坐标。保证所有单元格都不同,且没有一个单元格是 $ (n, 1) $。
- 保证所有测试用例的 $ k $ 之和不超过 $ 2 \cdot 10^5 $。

输出:
- 对于每个测试用例,首先输出 $ \alpha $ —— 如果鲍勃不给爱丽丝任何喷泉,爱丽丝的地块可以达到的最大大小。
- 然后输出 $ k $ 个非负整数 $ a_1, a_2, \dots, a_k $,其定义如上所述。

如果输出任何其他正数代替 $ 1 $,只要它适合 64 位有符号整数类型,它也将被识别为 $ 1 $。因此,这个问题的困难版本的解决方案也将通过简单版本的测试。题目大意: 这是一个关于划分田地的问题的简单版本,与困难版本的区别仅在于问题的要求。简单版本只需打印某些值是否非零。困难版本需要打印确切的值。 爱丽丝和鲍勃正在划分一个矩形田地,其大小为 $ n \times m $ ($ 2 \le n, m \le 10^9 $),行从上到下编号为 1 到 $ n $,列从左到右编号为 1 到 $ m $。行 $ r $ 和列 $ c $ 交叉的单元格表示为 $ (r, c) $。 鲍勃有 $ k $ ($ 2 \le k \le 2 \cdot 10^5 $)个喷泉,它们都位于田地中的不同单元格。爱丽丝负责划分田地,但她必须满足几个条件: - 为了划分田地,爱丽丝将从田地的左侧或顶部任意一个没有喷泉的单元格开始她的路径,并且每次向下或向右移动到相邻的单元格。她的路径将在田地的右侧或底部结束。 - 爱丽丝的路径将田地划分为两部分——一部分属于爱丽丝(包括她路径上的单元格),另一部分属于鲍勃。 - 爱丽丝将拥有包括单元格 $ (n, 1) $ 的部分。 - 鲍勃将拥有包括单元格 $ (1, m) $ 的部分。 爱丽丝希望以这种方式划分田地,以获得尽可能多的单元格。 鲍勃希望保留所有喷泉的所有权,但他可以给爱丽丝一个。首先输出整数 $ \alpha $ —— 如果鲍勃不给爱丽丝任何喷泉,爱丽丝的地块可以达到的最大可能大小(即,所有喷泉都留在鲍勃的地块上)。然后输出 $ k $ 个非负整数 $ a_1, a_2, \dots, a_k $,其中: - 如果鲍勃给爱丽丝第 $ i $ 个喷泉,爱丽丝的地块的最大可能大小没有增加(即,保持等于 $ \alpha $),则 $ a_i = 0 $; - 如果鲍勃给爱丽丝第 $ i $ 个喷泉,爱丽丝的地块的最大可能大小增加了(即,变得大于 $ \alpha $),则 $ a_i = 1 $。 输入输出数据格式: 输入: - 第一行包含一个整数 $ t $ ($ 1 \le t \le 10^4 $)——测试用例的数量。 - 每个测试用例的第一行包含三个整数 $ n $、$ m $ 和 $ k $ ($ 2 \le n, m \le 10^9 $,$ 2 \le k \le 2 \cdot 10^5 $)——田地的大小和喷泉的数量。 - 接下来 $ k $ 行,每行包含两个数字 $ r_i $ 和 $ c_i $ ($ 1 \le r_i \le n $,$ 1 \le c_i \le m $)——第 $ i $ 个喷泉所在单元格的坐标。保证所有单元格都不同,且没有一个单元格是 $ (n, 1) $。 - 保证所有测试用例的 $ k $ 之和不超过 $ 2 \cdot 10^5 $。 输出: - 对于每个测试用例,首先输出 $ \alpha $ —— 如果鲍勃不给爱丽丝任何喷泉,爱丽丝的地块可以达到的最大大小。 - 然后输出 $ k $ 个非负整数 $ a_1, a_2, \dots, a_k $,其定义如上所述。 如果输出任何其他正数代替 $ 1 $,只要它适合 64 位有符号整数类型,它也将被识别为 $ 1 $。因此,这个问题的困难版本的解决方案也将通过简单版本的测试。

加入题单

上一题 下一题 算法标签: