题意:
有两种操作:
① $1$ $l$ $r$ 表示区间$(l,r)$中不递减。
② $0$ $l$ $r$ 表示区间$(l,r)$中存在递减。
要求构造这个序列。
思路:
对于$1,l,r$中的每一个数等于前一个数,其余的数$a[i]=a[i-1]-1$。
对于$0,l,r$判断$a[l]$和$a[r]$的关系,若相等则不存在可构造序列。
代码:
1 //#include<bits/stdc++.h> 2 #include <set> 3 #include <map> 4 #include <stack> 5 #include <cmath> 6 #include <queue> 7 #include <cstdio> 8 #include <string> 9 #include <vector> 10 #include <cstring> 11 #include <iostream> 12 #include <algorithm> 13 14 #define ll long long 15 #define pll pair<ll,ll> 16 #define pii pair<int,int> 17 #define bug printf("********* ") 18 #define FIN freopen("input.txt","r",stdin); 19 #define FON freopen("output.txt","w+",stdout); 20 #define IO ios::sync_with_stdio(false),cin.tie(0) 21 #define ls root<<1 22 #define rs root<<1|1 23 #define pb push_back 24 25 using namespace std; 26 const int inf = 2e9 + 7; 27 const ll Inf = 1e18 + 7; 28 const int maxn = 2e5 + 5; 29 const int mod = 1e9 + 7; 30 31 int n, m; 32 int a[maxn]; 33 struct node 34 { 35 int op, l, r; 36 }p[maxn]; 37 38 int vis[maxn]; 39 40 int main() 41 { 42 scanf("%d %d", &n, &m); 43 for (int i = 1; i <= m; ++i) 44 { 45 scanf("%d %d %d", &p[i].op, &p[i].l, &p[i].r); 46 if (p[i].op == 1) 47 for (int j = p[i].l + 1; j <= p[i].r; ++j) vis[j] = 1; 48 } 49 a[1] = n; 50 for (int i = 2; i <= n; ++i) 51 { 52 if (vis[i] == 1) a[i] = a[i - 1]; 53 else a[i] = a[i - 1] - 1; 54 } 55 for (int i = 1; i <= m; ++i) 56 { 57 if (p[i].op) continue; 58 if (a[p[i].l] == a[p[i].r]) { 59 cout << "NO" << endl; 60 return 0; 61 } 62 } 63 cout << "YES" << endl; 64 for (int i = 1; i <= n; ++i) 65 { 66 if (i != 1) cout << " "; 67 cout << a[i]; 68 } 69 }