Educational Codeforces Round 67 (Rated for Div. 2) C. Vasya And Array

C. Vasya And Array

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.

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≤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 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.

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

代码:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <functional>
#include <ctime>
#include <iomanip>
#include <sstream>
#include <algorithm>
#define ll long long
#define ull unsigned long long
#define dd double
#define mes(x,y) memset(x,y,sizeof(x))
using namespace std;
 
const int maxn=2e4+9;
const int mod=1e9+7;
 
ll GCD(ll a,ll b) {//最大公约数
    return b == 0 ? a : GCD(b, a % b);
}
struct ode{
    ll x,y,z;
}a[2000];
int main() {
    std::ios::sync_with_stdio(false);
    ll n, m, i, j;
    ll x[2000], y[2000];
    while (cin >> n >> m) {
        mes(x, 0);
        mes(y, 0);
        for (i = 0; i < m; i++) {
            cin >> a[i].x >> a[i].y >> a[i].z;
            if (a[i].x == 1) {
                x[a[i].y]++;
                x[a[i].z]--;
            }
        }
        for (i = 1; i <= n; i++)
            x[i] += x[i - 1];
        y[0] = n;
        for (i = 1; i < n; i++)
            if (x[i])
                y[i] = y[i - 1];
            else
                y[i] = y[i - 1] - 1;
        bool flag = true;
        for (i = 0; i < m; i++)
            if (a[i].x == 0)
                if (is_sorted(y + a[i].y - 1, y + a[i].z))
                    flag = false;
        if (flag) {
            cout << "YES" << endl;
            for (i = 0; i < n; i++)cout << y[i] << " ";
            cout << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}
发布了148 篇原创文章 · 获赞 7 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_44417851/article/details/94405879