codeforces 1187C

题目来源链接:http://codeforces.com/problemset/problem/1187/C

C. Vasya And Array

Vasya has an array a1,a2,…,ana1,a2,…,an.

You don't know this array, but he told you mm facts about this array. The ii-th fact is a triple of numbers titi, lili and riri (0≤ti≤1,1≤li<ri≤n0≤ti≤1,1≤li<ri≤n) and it means:

  • if ti=1ti=1 then subbarray ali,ali+1,…,ariali,ali+1,…,ari is sorted in non-decreasing order;
  • if ti=0ti=0 then subbarray ali,ali+1,…,ariali,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] then he could give you three facts: t1=1,l1=2,r1=4t1=1,l1=2,r1=4 (the subarray [a2,a3,a4]=[1,1,3][a2,a3,a4]=[1,1,3] is sorted), t2=0,l2=4,r2=5t2=0,l2=4,r2=5 (the subarray [a4,a5]=[3,2][a4,a5]=[3,2] is not sorted), and t3=0,l3=3,r3=5t3=0,l3=3,r3=5 (the subarray [a3,a5]=[1,3,2][a3,a5]=[1,3,2] is not sorted).

You don't know the array aa. Find any array which satisfies all the given facts.

Input

The first line contains two integers nn and mm (2≤n≤1000,1≤m≤10002≤n≤1000,1≤m≤1000).

Each of the next mm lines contains three integers titi, lili and riri (0≤ti≤1,1≤li<ri≤n0≤ti≤1,1≤li<ri≤n).

If ti=1ti=1 then subbarray ali,ali+1,…,ariali,ali+1,…,ari is sorted. Otherwise (if ti=0ti=0) subbarray ali,ali+1,…,ariali,ali+1,…,ari is not sorted.

Output

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 nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the array aa, 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

题意概述:有一个数组A,不知道他具体是什么,但是有m个关于数组的事实,每个事实三个数:t,l,r,如果t等于1,那么数组a中第l个数到第r个数是非递减数列,如果是0,那么l到r则不是一个非递减数列(有一个数大于前一个就行),问这种数列是否存在,如果存在,随便输出一种可能的情况 

解题思路:这个题的数据范围很小,直接暴力就可以了,把题目中要求的非递减序列标记,没有标记的就是递减的部分,如果要求不是非递减序列不存在,就是“NO”,如果数组存在,把非递减序列部分输出为一个最大数,递减的部分直接按顺序减小

#include<iostream>
#include<queue>
#include<cstring> 
#include<cmath>
#include<map>
#include<algorithm>
#define up(i,x,y) for(i=x;i<y;i++)  
#define down(i,x,y) for(i=x;i>=y;i--)  
#define MAX(a,b) a>b?a:b
#define MIN(a,b) a<b?a:b
#define MAX(a,b,c) (a>b?(a>c?a:c):(b>c?b:c))
#define MIN(a,b,c) (a<b?(a<c?a:c):(b<c?b:c))
using namespace std;

typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int maxn = 100;
const int MAXN = 2750131;
ll T,n,m,i,j;
ll gcd(ll p,ll q)
{return q==0?p:gcd(q,p%q);}
struct point{
	int d,l,r;
}a[200005];

int main()
{
	bool b[2000];
	memset(b,false,sizeof(b));
	cin>>n>>m;
	int d,l,r,k=0;
	up(i,0,m){
		cin>>d>>l>>r;
		if(d==1){
			for(j=l+1;j<=r;j++){
				if(b[j]){
					continue;
				}
				else{
					b[j]=true;
				}
			}
		}
		else{
			a[k].d=d;
			a[k].l=l;
			a[k++].r=r;
		}
	}
	
	up(i,0,k){
		int flag=0;
		for(j=a[i].l+1;j<=a[i].r;j++){
			if(!b[j]){
				flag=1;break;
			}
		}
		if(!flag){
			cout<<"NO"<<endl;return 0;
		}
	}
	cout<<"YES"<<endl;
	k=0;
	for(i=1;i<=n;i++){
		if(b[i]){
			k=0;
		}
		else{
			k++;
		}
		cout<<n-k+1<<" ";
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值