CF1187C.Vasya And Array
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Vasya has an array a1,a2,…,an.
You don't know this array, but he told you m facts about this array. The i-th fact is a triple of numbers ti, li and ri (0≤ti≤1,1≤li<ri≤n) and it means:
- if ti=1 then subbarray ali,ali+1,…,ari is sorted in non-decreasing order;
- if ti=0 then subbarray ali,ali+1,…,ari is not sorted in non-decreasing order. A subarray is not sorted if there is at least one pair of consecutive elements in this subarray such that the former is greater than the latter.
For example if a=[2,1,1,3,2] then he could give you three facts: t1=1,l1=2,r1=4 (the subarray [a2,a3,a4]=[1,1,3] is sorted), t2=0,l2=4,r2=5 (the subarray [a4,a5]=[3,2] is not sorted), and t3=0,l3=3,r3=5 (the subarray [a3,a5]=[1,3,2] is not sorted).
You don't know the array a. Find any array which satisfies all the given facts.
瓦西里有一个数组 a1,a2,…,an。
你并不知道这个数组,但他告诉了你关于该数组的 m 条信息。第 i 条信息是一个三元组 ti、li 和 ri(其中 0≤ti≤1,1≤li<ri≤n),其含义如下:
- 若 ti=1,则子数组 ali,ali+1,…,ari 是非递减有序的;
- 若 ti=0,则子数组 ali,ali+1,…,ari 不是非递减有序的。当且仅当该子数组中存在至少一对相邻元素,使得前者大于后者时,称该子数组不是非递减有序的。
例如,若 a=[2,1,1,3,2],则他可能给出如下三条信息:t1=1,l1=2,r1=4(子数组 [a2,a3,a4]=[1,1,3] 是有序的);t2=0,l2=4,r2=5(子数组 [a4,a5]=[3,2] 是无序的);以及 t3=0,l3=3,r3=5(子数组 [a3,a4,a5]=[1,3,2] 是无序的)。
你并不知道数组 a 的具体取值。请找出任意一个满足所有给定信息的数组。
输入格式
The first line contains two integers n and m (2≤n≤1000,1≤m≤1000).
Each of the next m lines contains three integers ti, li and ri (0≤ti≤1,1≤li<ri≤n).
If ti=1 then subbarray ali,ali+1,…,ari is sorted. Otherwise (if ti=0) subbarray ali,ali+1,…,ari is not sorted.
第一行包含两个整数 n 和 m(2≤n≤1000,1≤m≤1000)。
接下来的 m 行每行包含三个整数 ti、li 和 ri(0≤ti≤1,1≤li<ri≤n)。
若 ti=1,则子数组 ali,ali+1,…,ari 是有序的;否则(即 ti=0),子数组 ali,ali+1,…,ari 是无序的。
输出格式
If there is no array that satisfies these facts in only line print NO (in any letter case).
If there is a solution, print YES (in any letter case). In second line print n integers a1,a2,…,an (1≤ai≤109) — the array a, satisfying all the given facts. If there are multiple satisfying arrays you can print any of them.
如果不存在满足这些条件的数组,则仅在一行中输出 NO(字母大小写任意)。
如果存在解,则首先输出 YES(字母大小写任意);第二行输出 n 个整数 a1,a2,…,an(其中 1≤ai≤109),即满足所有给定条件的数组 a。若存在多个满足条件的数组,输出任意一个即可。
输入输出样例
输入#1
7 4 1 1 3 1 2 5 0 5 6 1 6 7
输出#1
YES 1 2 2 3 5 4 4
输入#2
4 2 1 1 4 0 2 3
输出#2
NO
输入解题思路,AI测评打分。不知道怎么写?