CF1623B.Game on Ranges

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Alice and Bob play the following game. Alice has a set SS of disjoint ranges of integers, initially containing only one range [1,n][1, n]. In one turn, Alice picks a range [l,r][l, r] from the set SS and asks Bob to pick a number in the range. Bob chooses a number dd (l≤d≤rl \le d \le r). Then Alice removes [l,r][l, r] from SS and puts into the set SS the range [l,d−1][l, d - 1] (if l≤d−1l \le d - 1) and the range [d+1,r][d + 1, r] (if d+1≤rd + 1 \le r). The game ends when the set SS is empty. We can show that the number of turns in each game is exactly nn.

After playing the game, Alice remembers all the ranges [l,r][l, r] she picked from the set SS, but Bob does not remember any of the numbers that he picked. But Bob is smart, and he knows he can find out his numbers dd from Alice's ranges, and so he asks you for help with your programming skill.

Given the list of ranges that Alice has picked ([l,r][l, r]), for each range, help Bob find the number dd that Bob has picked.

We can show that there is always a unique way for Bob to choose his number for a list of valid ranges picked by Alice.

爱丽丝和鲍勃玩以下游戏。爱丽丝持有一个互不相交的整数区间集合 SS,初始时 SS 中仅包含一个区间 [1,n][1, n]。在每一轮中,爱丽丝从集合 SS 中选出一个区间 [l,r][l, r],并请鲍勃从中选择一个整数。鲍勃选择一个数 dd(满足 l≤d≤rl \le d \le r)。随后,爱丽丝将 [l,r][l, r] 从 SS 中移除,并向 SS 中加入区间 [l,d−1][l, d - 1](若 l≤d−1l \le d - 1)和 [d+1,r][d + 1, r](若 d+1≤rd + 1 \le r)。当集合 SS 为空时,游戏结束。可以证明:每局游戏的轮数恰好为 nn。

游戏结束后,爱丽丝记得她从集合 SS 中选取的所有区间 [l,r][l, r],但鲍勃却完全不记得自己所选的任何数字。不过鲍勃很聪明,他知道可以根据爱丽丝提供的这些区间推断出自己每次所选的数字 dd,因此他请求你借助编程能力来帮助他。

给定爱丽丝所选取的区间列表(即一系列 [l,r][l, r]),对其中每一个区间,请帮鲍勃找出他当时所选的数字 dd。

可以证明:对于爱丽丝给出的任意一组合法区间,鲍勃选择数字 dd 的方式总是唯一的。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤10001 \le t \le 1000). Description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤10001 \le n \le 1000).

Each of the next nn lines contains two integers ll and rr (1≤l≤r≤n1 \le l \le r \le n), denoting the range [l,r][l, r] that Alice picked at some point.

Note that the ranges are given in no particular order.

It is guaranteed that the sum of nn over all test cases does not exceed 10001000, and the ranges for each test case are from a valid game.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤10001 \le t \le 1000)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤10001 \le n \le 1000)。

接下来的 nn 行中,每行包含两个整数 ll 和 rr(1≤l≤r≤n1 \le l \le r \le n),表示爱丽丝在某个时刻所选的区间 [l,r][l, r]。

注意:这些区间以任意顺序给出。

保证所有测试用例的 nn 值之和不超过 10001000,且每个测试用例中的区间均来自一场合法的游戏。

输出格式

For each test case print nn lines. Each line should contain three integers ll, rr, and dd, denoting that for Alice's range [l,r][l, r] Bob picked the number dd.

You can print the lines in any order. We can show that the answer is unique.

It is not required to print a new line after each test case. The new lines in the output of the example are for readability only.

对每个测试用例,输出 nn 行。每行应包含三个整数 ll、rr 和 dd,表示对于 Alice 的区间 [l,r][l, r],Bob 选择的数为 dd。

各行的输出顺序可以任意。我们可以证明该答案是唯一的。

每个测试用例结束后无需额外输出换行符。示例输出中的换行仅为了提高可读性。

输入输出样例

  • 输入#1

    4
    1
    1 1
    3
    1 3
    2 3
    2 2
    6
    1 1
    3 5
    4 4
    3 6
    4 5
    1 6
    5
    1 5
    1 2
    4 5
    2 2
    4 4

    输出#1

    1 1 1
    
    1 3 1
    2 2 2
    2 3 3
    
    1 1 1
    3 5 3
    4 4 4
    3 6 6
    4 5 5
    1 6 2
    
    1 5 3
    1 2 1
    4 5 5
    2 2 2
    4 4 4

说明/提示

In the first test case, there is only 1 range [1,1][1, 1]. There was only one range [1,1][1, 1] for Alice to pick, and there was only one number 11 for Bob to pick.

In the second test case, n=3n = 3. Initially, the set contains only one range [1,3][1, 3].

  • Alice picked the range [1,3][1, 3]. Bob picked the number 11. Then Alice put the range [2,3][2, 3] back to the set, which after this turn is the only range in the set.
  • Alice picked the range [2,3][2, 3]. Bob picked the number 33. Then Alice put the range [2,2][2, 2] back to the set.
  • Alice picked the range [2,2][2, 2]. Bob picked the number 22. The game ended.

In the fourth test case, the game was played with n=5n = 5. Initially, the set contains only one range [1,5][1, 5]. The game's turn is described in the following table.

Game turn

Alice's picked range

Bob's picked number

The range set after

Before the game start

$ { [1, 5] } $

1

[1,5][1, 5]

33

$ { [1, 2], [4, 5] }$

2

[1,2][1, 2]

11

$ { [2, 2], [4, 5] } $

3

[4,5][4, 5]

55

$ { [2, 2], [4, 4] } $

4

[2,2][2, 2]

22

$ { [4, 4] } $

5

[4,4][4, 4]

44

$ { } $ (empty set)

在第一个测试用例中,只有一个区间 [1,1][1, 1]。爱丽丝只能选择这一个区间 [1,1][1, 1],而鲍勃只能选择其中唯一的数字 11。

在第二个测试用例中,n=3n = 3。初始时,集合中仅包含一个区间 [1,3][1, 3]。

  • 爱丽丝选择了区间 [1,3][1, 3],鲍勃选择了数字 11。随后爱丽丝将区间 [2,3][2, 3] 放回集合中,此时该区间成为集合中唯一存在的区间。
  • 爱丽丝选择了区间 [2,3][2, 3],鲍勃选择了数字 33。随后爱丽丝将区间 [2,2][2, 2] 放回集合中。
  • 爱丽丝选择了区间 [2,2][2, 2],鲍勃选择了数字 22。游戏结束。

在第四个测试用例中,游戏在 n=5n = 5 的条件下进行。初始时,集合中仅包含一个区间 [1,5][1, 5]。游戏各回合情况如下表所示。

游戏回合

爱丽丝选择的区间

鲍勃选择的数字

本轮操作后的区间集合

游戏开始前

$ { [1, 5] } $

1

[1,5][1, 5]

33

$ { [1, 2], [4, 5] }$

2

[1,2][1, 2]

11

$ { [2, 2], [4, 5] } $

3

[4,5][4, 5]

55

$ { [2, 2], [4, 4] } $

4

[2,2][2, 2]

22

$ { [4, 4] } $

5

[4,4][4, 4]

44

$ { } $(空集)

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

首页