307382: CF1348F. Phoenix and Memory
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Phoenix and Memory
题意翻译
## 【题目描述】 拍照啦!拍照啦!菲尼克斯有 $n$ 个朋友,朋友们的编号是$1$ ~ $n$。他的朋友们本来按某种特殊顺序排成一排,但菲尼克斯还没来得及按下快门,就有一只鸭子乱入,把原本排好的顺序搞得乱七八糟。 现在,菲尼克斯不得不重新排好顺序,但他记不清了QAQ!他只记得从左数起的第$i$个朋友的编号大小在 $a_i$ 和 $b_i$ 之间。该怎么办?他只好向你请教。请问根据他的记忆有没有唯一一种方法给他的朋友们排序? **一句话题意**:问是否存在**唯一**一个 $1$ ~ $n$ 的排列 $c$ ,满足 $a_i \leq c_i \leq b_i$ 。 ## 【输入格式】 第一行一个整数 $n$ ($1 \leq n \leq 2 \times 10^5$),表示菲尼克斯的朋友数。 接下来 $n$ 行,第 $i$ 行两个整数 $a_i$ 和 $b_i$ ( $1 \leq a_i \leq a_i \leq n$ ),表示菲尼克斯对从左数第 $i$ 个朋友编号的记忆。 **数据保证至少有一个符合题意的排列**。 ## 【输出格式】 如果存在唯一一个排列符合题意,输出 'YES',然后换一行输出 $n$ 个整数,表示原本的排列。 否则,输出 'NO',然后在接下来两行中输出任意两种不同的符合题意的排列,格式同上。若有多种答案,请输出任意一种。题目描述
Phoenix is trying to take a photo of his $ n $ friends with labels $ 1, 2, \dots, n $ who are lined up in a row in a special order. But before he can take the photo, his friends get distracted by a duck and mess up their order. Now, Phoenix must restore the order but he doesn't remember completely! He only remembers that the $ i $ -th friend from the left had a label between $ a_i $ and $ b_i $ inclusive. Does there exist a unique way to order his friends based of his memory?输入输出格式
输入格式
The first line contains one integer $ n $ ( $ 1 \le n \le 2\cdot10^5 $ ) — the number of friends. The $ i $ -th of the next $ n $ lines contain two integers $ a_i $ and $ b_i $ ( $ 1 \le a_i \le b_i \le n $ ) — Phoenix's memory of the $ i $ -th position from the left. It is guaranteed that Phoenix's memory is valid so there is at least one valid ordering.
输出格式
If Phoenix can reorder his friends in a unique order, print YES followed by $ n $ integers — the $ i $ -th integer should be the label of the $ i $ -th friend from the left. Otherwise, print NO. Then, print any two distinct valid orderings on the following two lines. If are multiple solutions, print any.
输入输出样例
输入样例 #1
4
4 4
1 3
2 4
3 4
输出样例 #1
YES
4 1 2 3
输入样例 #2
4
1 3
2 4
3 4
2 3
输出样例 #2
NO
1 3 4 2
1 2 4 3