AT_abc478_e.lt and le
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Determine whether there exists an integer sequence A of length N consisting of integers between 1 and N, inclusive, that satisfies all of the following Q conditions, and if it exists, find one.
The i-th condition (1≤i≤Q) is given by a triple of integers (ti,ui,vi), and is defined as follows.
- If ti=0: Aui≤Avi
- If ti=1: Aui<Avi
If there are multiple sequences satisfying all conditions, you may output any of them.
判断是否存在一个长度为 N 的整数序列 A,其每个元素均为 1 到 N(含)之间的整数,且满足以下全部 Q 个条件;若存在,构造出其中一个满足条件的序列。
第 i 个条件(1≤i≤Q)由一个三元组整数 (ti,ui,vi) 给出,定义如下:
- 若 ti=0:Aui≤Avi
- 若 ti=1:Aui<Avi
若存在多个满足所有条件的序列,输出任意一个即可。
输入格式
The input is given from Standard Input in the following format:
N Q
t1 u1 v1
t2 u2 v2
⋮
tQ uQ vQ
输入从标准输入中按以下格式给出:
N Q
t1 u1 v1
t2 u2 v2
⋮
tQ uQ vQ
输出格式
On the first line, output Yes if an integer sequence satisfying the conditions exists, and No otherwise. If you output Yes on the first line, choose one integer sequence satisfying the conditions and output its elements, separated by spaces, on the second line. If there are multiple sequences satisfying all conditions, you may choose any of them.
第一行输出 Yes(如果存在满足条件的整数序列),否则输出 No。若第一行输出 Yes,则在第二行输出一个满足条件的整数序列,各元素之间用空格分隔。若存在多个满足所有条件的序列,任选其一即可。
输入输出样例
输入#1
7 8 0 1 4 0 2 6 0 3 2 1 3 5 0 4 1 0 4 3 1 5 7 0 6 7
输出#1
Yes 1 4 2 1 3 5 6
输入#2
1 1 1 1 1
输出#2
No
输入#3
15 20 0 9 8 1 6 1 0 6 8 0 11 1 0 4 2 1 11 12 0 4 14 1 10 1 0 12 12 1 7 12 1 13 1 1 5 9 1 10 14 1 14 1 1 8 12 0 10 12 1 4 15 1 3 9 0 5 14 0 10 2
输出#3
Yes 15 14 10 7 6 5 4 12 11 3 2 13 1 9 8
说明/提示
Sample 1 Explanation:
Let A=(1,4,2,1,3,5,6); this is an integer sequence of length 7 consisting of integers between 1 and 7, inclusive. Here, for example, the first condition A1≤A4 holds since 1≤1. The other seven conditions also hold, so the output corresponding to A=(1,4,2,1,3,5,6) is considered correct.
Additionally, A=(1,1,1,1,2,2,3), A=(3,5,4,3,6,7,7), and others also satisfy the conditions, so outputting these is also considered correct.
Sample 2 Explanation:
There is no integer sequence A such that A1<A1 holds.
Constraints
- 1≤N≤2×105
- 1≤Q≤2×105
- ti∈{0,1} (1≤i≤Q)
- 1≤ui≤N (1≤i≤Q)
- 1≤vi≤N (1≤i≤Q)
- All input values are integers.
样例 1 解释:
令 A=(1,4,2,1,3,5,6);这是一个长度为 7 的整数序列,其中每个元素均为 1 到 7(含端点)之间的整数。例如,第一个约束条件 A1≤A4 成立,因为 1≤1。其余七个约束条件也均成立,因此输出 A=(1,4,2,1,3,5,6) 被视为正确。
此外,A=(1,1,1,1,2,2,3)、A=(3,5,4,3,6,7,7) 等序列也满足所有约束条件,因此输出这些序列同样被视为正确。
样例 2 解释:
不存在满足 A1<A1 的整数序列 A。
约束条件
- 1≤N≤2×105
- 1≤Q≤2×105
- ti∈{0,1} (1≤i≤Q)
- 1≤ui≤N (1≤i≤Q)
- 1≤vi≤N (1≤i≤Q)
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?