「CF1187C」Vasya And Array【构造】

C. Vasya And Array

time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output

Vasya has an array a 1 , a 2 , … , a n a_1,a_2,…,a_n a1,a2,,an.
You don’t know this array, but he told you m m m facts about this array. The i − t h i-th ith fact is a triple of numbers t i t_i ti, l i l_i li and r i r_i ri ( 0 ≤ t i ≤ 1 , 1 ≤ l i &lt; r i ≤ n ) (0\leq t_i\leq1,1\leq l_i&lt;r_i\leq n) (0ti1,1li<rin) and it means:

if t i = 1 t_i=1 ti=1 then subbarray a l i , a l i + 1 , … , a r i a_{l_i},a_{l_{i+1}},…,a_{r_i} ali,ali+1,,ari is sorted in non-decreasing order;
if t i = 0 t_i=0 ti=0 then subbarray a l i , a l i + 1 , … , a r i a_{l_i},a_{l_{i+1}},…,a_{r_i} 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 ] a=[2,1,1,3,2] a=[2,1,1,3,2] then he could give you three facts: t 1 = 1 , l 1 = 2 , r 1 = 4 t_1=1,l_1=2,r_1=4 t1=1,l1=2,r1=4 (the subarray [ a 2 , a 3 , a 4 ] = [ 1 , 1 , 3 ] [a_2,a_3,a_4]=[1,1,3] [a2,a3,a4]=[1,1,3] is sorted), t 2 = 0 , l 2 = 4 , r 2 = 5 t_2=0,l_2=4,r_2=5 t2=0,l2=4,r2=5 (the subarray [ a 4 , a 5 ] = [ 3 , 2 ] [a_4,a_5]=[3,2] [a4,a5]=[3,2] is not sorted), and t 3 = 0 , l 3 = 3 , r 3 = 5 t_3=0,l_3=3,r_3=5 t3=0,l3=3,r3=5 (the subarray [ a 3 , a 5 ] = [ 1 , 3 , 2 ] [a_3,a_5]=[1,3,2] [a3,a5]=[1,3,2] is not sorted).

You don’t know the array ?. Find any array which satisfies all the given facts.

Input

The first line contains two integers n n n and m m m ( 2 ≤ n ≤ 1000 , 1 ≤ m ≤ 1000 ) (2\leq n\leq1000,1\leq m \leq1000) (2n1000,1m1000).
Each of the next ? lines contains three integers t i , l i   a n d   r i ( 0 ≤ t i ≤ 1 , 1 ≤ l i &lt; r i ≤ n ) t_i, l_i\ and\ r_i (0\leq t_i\leq1,1\leq l_i&lt;r_i\leq n) ti,li and ri(0ti1,1li<rin).
If t i = 1 t_i=1 ti=1 then subbarray a l i , a l i + 1 , … , a r i a_{l_i},a_{l_{i+1}},…,a_{r_i} ali,ali+1,,ari is sorted. Otherwise (if t i = 0 t_i=0 ti=0) subbarray a l i , a l i + 1 , … , a r i a_{l_i},a_{l_{i+1}},…,a_{r_i} ali,ali+1,,ari is not sorted.

Output

If there is no array that satisfies these facts in only line print N O NO NO (in any letter case).

If there is a solution, print Y E S YES YES (in any letter case). In second line print n n n integers a 1 , a 2 , … , a n ( 1 ≤ a i ≤ 1 0 9 ) a_1,a_2,…,a_n (1\leq a_i\leq10^9) a1,a2,,an(1ai109) — the array a a a, satisfying all the given facts. If there are multiple satisfying arrays you can print any of them.

Examples

input
7 4
1 1 3
1 2 5
0 5 6
1 6 7
output
YES
1 2 2 3 5 4 4
input
4 2
1 1 4
0 2 3
output
NO

题意

  • 就是构造一个长度为 n n n的数组,然后给出 m m m条描述条件,分为两种描述,一种是描述区间 [ l , r ] [l,r] [l,r]内的数单调不减,另一种描述 [ l , r ] [l,r] [l,r]内的数不是单调不减

题解

  • 计需要构造的数组为 a a a,用 m a r k [ i ] mark[i] mark[i]表示 a [ i + 1 ] a[i+1] a[i+1]是否需要大于等于 a [ i ] a[i] a[i],当给出第一种描述时,位置 [ l , r − 1 ] [l,r-1] [l,r1]内的位置的 m a r k mark mark值都要标记为 1 1 1,存下第二种描述,处理完第一种后,对于每一个第二种描述,检查 [ l , r − 1 ] [l,r-1] [l,r1]内的 m a r k mark mark是否有 0 0 0的情况,显然,如果没有,这种描述是无解的, c h e c k check check所有第二种描述都没问题之后,另 a [ 1 ] = n a[1]=n a[1]=n,然后对于 1 ≤ i &lt; n 1\leq i&lt;n 1i<n,如果 m a r k [ i ] = 1 mark[i]=1 mark[i]=1,不妨令 a [ i + 1 ] = a [ i ] a[i+1]=a[i] a[i+1]=a[i],否则令 a [ i + 1 ] = a [ i ] − 1 a[i+1]=a[i]-1 a[i+1]=a[i]1;
  • 感觉典型 C F CF CF题特点啊,想清楚代码很短,不想好直接写 F S T FST FST H a c k e d Hacked Hacked,还贼长贼长,这题列表全挂了
#include<bits/stdc++.h>

using namespace std;
const int maxn=1005;

int a[maxn][3],mark[maxn];

int main()
{
	int n,m;scanf("%d %d",&n,&m);
	for(int i=1,t,l,r;i<=m;i++){
		scanf("%d %d %d",&a[i][0],&a[i][1],&a[i][2]);
		if(a[i][0]) for(int j=a[i][1];j<a[i][2];j++) mark[j]=1;
	}
	for(int i=1;i<=m;i++){
		bool ok=false;
		if(!a[i][0]){
			for(int j=a[i][1];j<a[i][2];j++){
				if(!mark[j]) {ok=true;break;}
			}
			if(!ok) return printf("NO\n"),0;
		}
	}
	int ans=n+1;
	printf("YES\n");
	for(int i=1;i<=n;i++) printf("%d%c",mark[i-1]?ans:--ans,i==n?'\n':' ');
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值