Educational Codeforces Round 6 C. Pearls in a Row

  • 题意:一个3e5范围的序列;要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能出现一次。
  • 策略:

    1. 延伸:这里指的延伸如当发现1…1如果以最后出现重叠的数为右边界则就表示左延伸,若以1.0.1..0第二个0前一个位置作为右边界就为右延伸;
    2. 开始时想是右延伸,考虑到可能只出现一组两个数相同,认为向左延伸会出错,但是直接WA了之后,发现这并不是题目的坑点(其实只需将最后一组改成左右延伸就可以了),给一组数据就知道向右延伸是错误的:

      数据: n = 5, 1 1 0 0 1若是右延伸,则为 【1 1 0】,后面0 1不能配对,其实这里就直接说明了只要存在两个数相同,就不会出现无解的情况;
    3. 左延伸,一遇到里面还存有这个数据,直接往l[],R[]里面存区间,当然l是以上一个r为左边界的;最火一组数据让右边界等于n即可;
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 3e5;
set<int> Set;
int L[MAXN],R[MAXN];
int main()
{
int i,n,x,l = 1,cnt = 0;
cin>>n;
for(i = 1;i <= n;i++){
scanf("%d",&x);
if(Set.count(x)){
L[++cnt] = l;
R[cnt] = i;
l = i + 1;
Set.clear();
}else Set.insert(x);
}
if(cnt == 0) return puts("-1"),0;
R[cnt] = n;
printf("%d\n",cnt);
for(i = 1;i <= cnt;i++)
printf("%d %d\n",L[i],R[i]);
}

Educational Codeforces Round 6 C. Pearls in a Row的更多相关文章

  1. Educational Codeforces Round 6 C. Pearls in a Row set

    C. Pearls in a Row There are n pearls in a row. Let's enumerate them with integers from 1 to n from ...

  2. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  3. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  4. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  5. [Educational Codeforces Round 16]B. Optimal Point on a Line

    [Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...

  6. [Educational Codeforces Round 16]A. King Moves

    [Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...

  7. Educational Codeforces Round 9

    Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...

  8. Educational Codeforces Round 37

    Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...

  9. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

随机推荐

  1. 深入浅出Android动态载入jar包技术

    在实际项目中.因为某些业务频繁变更而导致频繁升级client的弊病会造成较差的用户体验,而这也恰是Web App的优势,于是便衍生了一种思路.将核心的易于变更的业务封装在jar包里然后通过网络下载下来 ...

  2. [Android]使用platform密钥来给apk文件签名的命令

    1.使用platform密钥对apk进行签名 1.1.进入<Android_Source_Path>/build/target/product/security,找到[platform.p ...

  3. 对ContentProvider中getType方法的一点理解

    在上篇博客中我们介绍了自定义ContentProvider,但是遗漏掉了一个方法,那就是getType,自定义ContentProvider一般用不上getType方法,但我们还是一起来探究下这个方法 ...

  4. textarea限制字符数

    html代码: <div class="remark_edit J_Remark_Edit"> <div class="tip-body"&g ...

  5. print之模块化

    这里参考特权同学的模块化思想,将常用的print等任务模块化,便于直接调用,提高代码的效率和易读性.现转载之,以供日后的学习和工作参考. print模块参考代码如下: //============== ...

  6. c3p0配置文件报错 对实体 "characterEncoding" 的引用必须以 ';' 分隔符结尾。

    原配置文件: 异常截图: 百度可知: 在xml的配置文件中 :要用  &   代替 更改后配置文件:

  7. ACM——简单排序

    简单选择排序 时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte总提交:836            测试通过:259 描述 给定输入排序元素 ...

  8. c#调用c++ dll(一)

    首先来说说c++中的dll 核心的一些知识 比较大的应用程序都由很多模块组成,这些模块分别完成相对独立的功能,它们彼此协作来完成整个软件系统的工作.可能存在一些模块的功能较为通用,在构造其它软件系统时 ...

  9. JS修改JSON中key的方法

    function modifyJosnKey(json,oddkey,newkey){ var val=json[oddkey]; delete json[oddkey]; json[newkey]= ...

  10. Struts2 多文件下载

    Step1:导入支持jar包 commons-fileupload-1.3.1.jar commons-io-2.4.jar jstl-1.2.jar standard-1.1.2.jar commo ...