Vasya And Array CodeForces - 1187C (构造)

Vasya And Array

题意:

给你一个序列,再给你一些区间

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 }

原文地址:https://www.cnblogs.com/DreamACMer/p/12694167.html

时间: 2024-10-31 19:30:40

Vasya And Array CodeForces - 1187C (构造)的相关文章

codeforces 671C Ultimate Weirdness of an Array 线段树+构造

题解上说的很清楚了,我照着写的,表示膜拜题解 然后时间复杂度我觉得应该是O(nlogn),虽然常数略大,预处理和倒着扫,都是O(nlogn) #include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> #include <vector> using namespace std; typedef long long LL; const int N = 2

B - Save the problem! CodeForces - 867B 构造题

B - Save the problem! CodeForces - 867B 这个题目还是很简单的,很明显是一个构造题,但是早训的时候脑子有点糊涂,想到了用1 2 来构造, 但是去算这个数的时候算错了... 用1 2 来构造 可以先枚举一些数来找找规律. 1 1 2 2 3 1 1 1    2 1 1 4 .... 可以发现每一个数都是 n/2+1 的可能, 所以反过来推过去就是 (s-1)*2  或者(s-1)*2+1 这个(s-1)*2+1的答案才是正确答案 因为 这个s可以==1 #i

Vasya and Basketball CodeForces - 493C

Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of

Imbalanced Array CodeForces - 817D (思维+单调栈)

You are given an array a consisting of n elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance valuesof all

Johnny Solving CodeForces - 1103C (构造,图论)

大意: 无向图, 无重边自环, 每个点度数>=3, 要求完成下面任意一个任务 找一条结点数不少于n/k的简单路径 找k个简单环, 每个环结点数小于n/k, 且不为3的倍数, 且每个环有一个特殊点$x$, $x$只属于这一个环 任选一棵生成树, 若高度>=n/k, 直接完成任务1, 否则对于叶子数一定不少于k, 而叶子反向边数>=2, 一定可以构造出一个环 #include <iostream> #include <algorithm> #include <c

Codeforces 1188A 构造

题意:给你一颗树,树的边权都是偶数,并且边权各不相同.你可以选择树的两个叶子结点,并且把两个叶子结点之间的路径加上一个值(可以为负数),问是否可以通过这种操作构造出这颗树?如果可以,输出构造方案.初始树的边权都是0. 思路:A1很简单,只要判断是否有度数为2的点就可以了.对于A2, 由于边权各不相同,所以A1的结论同样适用.现在我们来构造一组答案.官方题解的构造方式是这样的:我们假设要让一个节点u到叶子结点v的路径都加上一个值x,并且知道叶子结点l1, l2都可以到达u,我们执行以下操作:v到l

Powerful array CodeForces - 86D (莫队算法)

An array of positive integers a1,?a2,?...,?an is given. Let us consider its arbitrary subarray al,?al?+?1...,?ar, where 1?≤?l?≤?r?≤?n. For every positive integer s denote by Ks the number of occurrences of s into the subarray. We call the power of th

E Minimum Array ( Codeforces Round #555 (Div. 3) )

You are given two arrays aa and bb, both of length nn. All elements of both arrays are from 00 to n−1n−1. You can reorder elements of the array bb (if you want, you may leave the order of elements as it is). After that, let array cc be the array of l

Powerful array CodeForces - 86D(莫队)

给你n个数,m次询问,Ks为区间内s的数目,求区间[L,R]之间所有Ks*Ks*s的和.1<=n,m<=200000.1<=s<=10^6 #include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <set> #include <vector> #includ