Vasya And Array CodeForces - 1187C (构造)
Posted dreamacmer
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Vasya And Array CodeForces - 1187C (构造)相关的知识,希望对你有一定的参考价值。
题意:
给你一个序列,再给你一些区间
t = 1时说明这些区间时非递减的
t = 0 时说明这些区间至少有一对数字 arr[i] > arr[i - 1]
思路:
只要左边的区间必然右边的区间大就好了 , 非递减区间中的数字都赋值为一样的数字
因为n只有1000 , 把初值cnt赋值为1e6 , 每次给区间赋值的时候 -1000
把第一种情况的区间赋值完成之后,剩下的还没有赋值的部分,都赋值为单调递减序列就可以了
1 #include<cstdio> 2 #include<string.h> 3 #include<algorithm> 4 #include<cmath> 5 #include<iostream> 6 #include<vector> 7 #include<queue> 8 #include<set> 9 #include<map> 10 #include<cctype> 11 #define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) 12 #define mem(a,x) memset(a,x,sizeof(a)) 13 #define lson rt<<1,l,mid 14 #define rson rt<<1|1,mid + 1,r 15 #define P pair<int,int> 16 #define ull unsigned long long 17 using namespace std; 18 typedef long long ll; 19 const int maxn = 1e6 + 10; 20 const ll mod = 998244353; 21 const int inf = 0x3f3f3f3f; 22 const long long INF = 0x3f3f3f3f3f3f3f3f; 23 const double eps = 1e-7; 24 inline ll read() 25 { 26 ll X = 0, w = 0; char ch = 0; 27 while (!isdigit(ch)) { w |= ch == ‘-‘; ch = getchar(); } 28 while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar(); 29 return w ? -X : X; 30 } 31 int arr[maxn] , brr[maxn]; 32 int n, m; 33 struct node 34 { 35 int l, r, judge; 36 }q[maxn]; 37 38 int cmp(struct node& a, struct node& b) 39 { 40 if (a.judge == b.judge) return a.l < b.l; 41 return a.judge > b.judge; 42 } 43 int main() 44 { 45 while (~scanf("%d %d", &n, &m)) 46 { 47 int cnt = 0; 48 int flag = 1; 49 for (int i = 1; i <= m; ++i) 50 { 51 q[i].judge = read(), q[i].l = read(), q[i].r = read(); 52 } 53 sort(q + 1, q + 1 + m, cmp); 54 for (int i = 1; i <= m; ++i) 55 { 56 if (q[i].judge == 1) 57 { 58 if(arr[q[i].l] == 0) cnt -= 1000; 59 for (int j = q[i].l; j <= q[i].r; ++j) arr[j] = cnt; 60 } 61 } 62 for (int i = 1; i <= n; ++i) 63 { 64 if (arr[i] == 0) arr[i] = arr[i - 1] - 1; 65 } 66 for (int i = 1; i <= m; ++i) 67 { 68 69 if (q[i].judge == 0) 70 { 71 int tmp = 0; 72 for (int j = q[i].l; j < q[i].r; ++j) 73 { 74 if (arr[j] > arr[j + 1]) 75 { 76 tmp = 1; 77 break; 78 } 79 } 80 if (tmp == 0) 81 { 82 flag = 0; 83 break; 84 } 85 } 86 } 87 if (flag == 0) 88 { 89 cout << "No" << endl; 90 } 91 else 92 { 93 cout << "Yes" << endl; 94 for (int i = 1; i <= n; ++i) 95 { 96 cout << arr[i] + 1000000 << " "; 97 if (i == n) cout << endl; 98 } 99 } 100 101 } 102 return 0; 103 }
以上是关于Vasya And Array CodeForces - 1187C (构造)的主要内容,如果未能解决你的问题,请参考以下文章
Vasya And Array CodeForces - 1187C (构造)
CF1093F Vasya and Array [DP+容斥]
Codeforces1187 C. Vasya And Array(思维,构造)
Educational Codeforces Round 56 (Rated for Div. 2) F - Vasya and Array dp好题