You are on page 1of 1

#include <iostream>

#include <vector>

using namespace std;

const int N = 1005;

int n, m, t, l, r, i, j;
bool mustBeSorted[N]; // v[i] must be < v[i+1]
vector<pair<int, int>> t0;

int main()
{
cin>>n>>m;
while(m--)
{
cin>>t>>l>>r;
if(t == 1)
for(i = l; i < r; i++)
mustBeSorted[i] = true;
else
t0.push_back({l, r});
}

bool solutionExists = true;


for(auto i : t0)
{
bool canBeNotSorted = false;
for(j = i.first; j < i.second && !canBeNotSorted; j++)
if(!mustBeSorted[j])
canBeNotSorted = true;

if(!canBeNotSorted)
{
solutionExists = false;
break;
}
}

if(solutionExists)
{
cout<<"YES\n";
int cnt = 10000;
for(i = 1; i <= n; i++, cnt++)
{
if(!mustBeSorted[i-1])
cnt -= 2;

cout<<cnt<<' ';
}
}
else
cout<<"NO";
return 0;
}

You might also like