链接:https://ac.nowcoder.com/acm/contest/634/A

来源:牛客网

小y的序列

时间限制:C/C++ 1秒,其他语言2秒

空间限制:C/C++ 32768K,其他语言65536K

Special Judge, 64bit IO Format: %lld

题目描述

小y有一块长度为n的布匹。颜色全部为0。他要给这个布匹染色。他总共有m种染料。小y认为一种染料用多次是不和谐的。所以每种染料会被用刚好一次。也就是说小y要给这块布匹染m次色。第i次会把L_iL

i



到R_iR

i



这个区间染成颜色i。现在给出最终布匹每段的颜色。请你输出一种染色方案。数据保证有解

输入描述:

输入共两行。

第一行两个个正整数n,m,表示布匹的长度和染料的数量

第二行n个用空格隔开的正整数,第i个数字a_ia

i



表示第i个布匹的颜色。

输出描述:

输出m行。

第i行包含两个正整数L_i,R_iL

i



,R

i



,表示第i次染色的区间。

示例1

输入

复制

3 3

1 2 3

输出

复制

1 3

2 3

3 3

备注:

1 \leq n ,m\leq 10^51≤n,m≤10

5

0 \leq a_i \leq m0≤a

i



≤m

1\le L_i \le R_i\le n1≤L

i



≤R

i



≤n

思路:

本题细节过多,需要仔细读题。

我们用两个数组 l[i] ,r[i] 分别代表 颜色i出现的最左位置和最右位置,

如果这个颜色在最终数组中没有出现,那么一定是被编号比它大的颜色覆盖掉了,

那么对于没有出现的颜色,我们就输出出现过的编号最大的颜色所在的位置即可。

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) {ll ans = 1; while (b) {if (b % 2)ans = ans * a % MOD; a = a * a % MOD; b /= 2;} return ans;}
inline void getInt(int* p);
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int l[maxn];
int r[maxn];
int n;
int m;
int main()
{
//freopen("D:\\code\\text\\input.txt","r",stdin);
//freopen("D:\\code\\text\\output.txt","w",stdout);
cin>>n>>m;
repd(i,1,m)
{
l[i]=inf;
}
int x; int ok;
repd(i,1,n)
{
cin>>x;
l[x]=min(l[x],i);
r[x]=max(r[x],i);
}
for(int i=m;i>=1;i--)
{
if(l[i]!=inf)
{
ok=l[i];
break;
}
}
repd(i,1,m)
{
// cout<<i<<endl;
if(l[i]==inf)
{
cout<<ok<<" "<<ok<<endl;
continue;
}
// cout<<endl;
cout<<l[i]<<" "<<r[i]<<endl;
}
return 0;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 - ch + '0';
}
}
else {
*p = ch - '0';
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 + ch - '0';
}
}
}

牛客练习赛44 A 小y的序列 (模拟,细节)的更多相关文章

  1. 牛客练习赛44 C 小y的质数 (数论,容斥定理)

    链接:https://ac.nowcoder.com/acm/contest/634/C 来源:牛客网 题目描述 给出一个区间[L,R],求出[L,R]中孪生质数有多少对. 由于这是一个区间筛质数的模 ...

  2. 牛客练习赛44 B 小y的线段 (思维)

    链接:https://ac.nowcoder.com/acm/contest/634/B 来源:牛客网 题目描述 给出n条线段,第i条线段的长度为a_ia i ​ ,每次可以从第i条线段的j位置跳到第 ...

  3. 牛客练习赛48 C 小w的糖果 (数学,多项式,差分)

    牛客练习赛48 C 小w的糖果 (数学,多项式) 链接:https://ac.nowcoder.com/acm/contest/923/C来源:牛客网 题目描述 小w和他的两位队友teito.toki ...

  4. 牛客练习赛48 A· 小w的a+b问题 (贪心,构造,二进制)

    牛客练习赛48 A· 小w的a+b问题 链接:https://ac.nowcoder.com/acm/contest/923/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C ...

  5. 牛客练习赛44 C:小y的质数

    链接:https://ac.nowcoder.com/acm/contest/634/C?tdsourcetag=s_pcqq_aiomsg 来源:牛客网 题目描述 给出一个区间\([L,R]\),求 ...

  6. 牛客练习赛44 B:小y的线段

    链接:https://ac.nowcoder.com/acm/contest/634/B 来源:牛客网 题目描述 给出\(n\)条线段,第\(i\)条线段的长度为\(a_i\),每次可以从第\(i\) ...

  7. 牛客练习赛44 B题 (思维)

    链接:https://ac.nowcoder.com/acm/contest/634/B 来源:牛客网 给出n条线段,第i条线段的长度为ai, 每次可以从第i条线段的j位置跳到第i + 1条线段的j+ ...

  8. 牛客练习赛48 D 小w的基站网络

    链接:https://ac.nowcoder.com/acm/contest/923/D来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言52428 ...

  9. 5.15 牛客挑战赛40 B 小V的序列 关于随机均摊分析 二进制

    LINK:小V的序列 考试的时候 没想到正解 于是自闭. 题意很简单 就是 给出一个序列a 每次询问一个x 问序列中是否存在y 使得x^y的二进制位位1的个数<=3. 容易想到 暴力枚举. 第一 ...

随机推荐

  1. 使用 joblib 对 Pandas 数据进行并行处理

    使用 joblib 对 Pandas 数据进行并行处理 如果需要对一个很大的数据集进行操作,而基于一列数据生成新的一列数据可能都需要耗费很长时间. 于是可以使用 joblib 进行并行处理. 假设我们 ...

  2. shell中命令作为变量使用

    说明:必须要带上$ ,否则报错 ENCRYPTION_KEY=$( /dev/urandom | od -An -t x | tr -d ' ') echo ${ENCRYPTION_KEY}

  3. 【转】Apache HBase 问题排查思路

    [From]https://www.itcodemonkey.com/article/9426.html HBCK - HBCK检查什么? (1)HBase Region一致性 集群中所有region ...

  4. docker 的安装和镜像

    一.docker的 安装 : 第一种: yum -y install docker systemctl start docker.service systemctl status docker 第二种 ...

  5. 图片和Base64字符串互转

    图片URL转成Base64字符串 /// <summary> /// 通过Url获取到Image格式的文件 /// </summary> /// <param name= ...

  6. LCA模板(数剖实现)

    题目链接:https://www.luogu.org/problemnew/show/P3379 题意:LCA模板题. 思路:今天开始学树剖,先拿lca练练.树剖解lca,两次dfs复杂度均为O(n) ...

  7. PostgreSQL查询数据库中包含某种类型的表有哪些

    and c.relnamespace = n.oid and nspname = 'public' and a.atttypid = t.oid and typname = 'TEXT' and c. ...

  8. sql server查询数据库连接数

    设置最大连接数 下面的T-SQL 语句可以配置SQL Server 允许的并发用户连接的最大数目. exec sp_configure 'show advanced options', 1exec s ...

  9. 树状数组+二维前缀和(A.The beautiful values of the palace)--The Preliminary Contest for ICPC Asia Nanjing 2019

    题意: 给你螺旋型的矩阵,告诉你那几个点有值,问你某一个矩阵区间的和是多少. 思路: 以后记住:二维前缀和sort+树状数组就行了!!!. #define IOS ios_base::sync_wit ...

  10. MySQL 必备工具使用的6个锦囊妙计!

    这款工具是 MySQL 一个重要分支 percona 的,名称叫做 percona-toolkit(一把锋利的瑞士军刀),它呢是一组命令的集合.今儿给大家介绍几个我们在生产环境中最长用到的. 工具包的 ...