Vasya And Array CodeForces-1187C (Construction)

Vasya And Array

Topic:

Give you a sequence and then give you some intervals

t = 1 means that these intervals are non-decreasing

t = 0 means that there is at least one pair of numbers in these intervals arr [i]> arr [i-1]

Ideas:

As long as the interval on the left is necessarily large on the right, all numbers in the non-decreasing interval are assigned the same number

Because n is only 1000, the initial value cnt is assigned to 1e6, and each time the interval is assigned -1000

After the assignment of the interval in the first case is completed, the remaining parts that have not been assigned are all assigned to a monotonically decreasing sequence.

  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 }
View Code

 

Guess you like

Origin www.cnblogs.com/DreamACMer/p/12694167.html