Vasya has an array a1,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≤n) and it means:
if ti=1ti=1 then subbarray ali,ali+1,…,ari is sorted in non-decreasing order;
if ti=0ti=0 then subbarray ali,ali+1,…,ar 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 aa. Find any array which satisfies all the given facts.
Input
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≤n0≤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.
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,…,an(1≤ai≤109) — the array 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
题意: 构造数组,两种情况:一种是当t =1 时,ai~aj为非递减的形式,另一种是当t=0时,ai ~aj不为非递减形式(记住这不是递减,就是这个范围内只要有任意两个相邻元素为递减就行,其它的按照非递减),所以,我们先将t=1时的数组下先标记好,然后再去遍历t=0时的情况,只要在范围内有任意一组满足不按非递减就行。
附上AC代码:
#include <bits/stdc++.h>
using namespace std;
int num[1001][1001];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int t[1001],a[1001],b[1001],flag=0;
for(int i=0;i<m;i++)
{
scanf("%d%d%d",&t[i],&a[i],&b[i]);
if(t[i]==1){
for(int j=a[i];j<b[i];j++){
num[j][j+1]=1;
}
}
}
int book=0;
for(int i=0;i<m;i++)
{
if(!t[i]){
int flag2=0;
for(int j=a[i];j<b[i];j++)
{
if(num[j][j+1]==0){
flag2=1;
}
}
if(!flag2){
book=1;break;
}
}
}
if(!book)
{
printf("YES\n");
int tr=1001;
for(int i=1;i<=n;i++)
{
if(num[i-1][i]==0)
tr--;
printf("%d ",tr);
}
printf("\n");
}
else
printf("NO\n");
return 0;
}