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. [Javascript] Lodash: Refactoring Simple For Loops (_.find, _.findLast, _.filter)

    This lesson shows how to refactor your old loops into using a simpler and more powerful lodash-style ...

  2. 在Linux环境中使用Ext3文件系统

      Linux缺省情况下使用的文件系统为Ext2,ext2文件系统的确高效稳定.但是,随着Linux系统在关键业务中的应用,Linux文件系统的弱点也渐渐显露出来了:其中系统缺省使用的ext2文件系统 ...

  3. 匹配url - 正则表达式

    /^\/(.+)\/$/g.exec(req.url)

  4. elasticsearch学习一、安装和配置

    原文链接:http://jingyan.baidu.com/article/48206aead42b53216bd6b372.html ElasticSearch是一个基于Lucene的搜索服务器.它 ...

  5. Devexpress 使用经验 —— ASPxGridView命令行自定义按钮灵活使用

    ASPX <dx:ASPxGridView ID="ASPxGridView1" runat="server" DataSourceID="Ob ...

  6. nyoj914Yougth的最大化(二分搜索 + 贪心)

    Yougth的最大化 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 Yougth现在有n个物品的重量和价值分别是Wi和Vi,你能帮他从中选出k个物品使得单位重量的价值最大吗 ...

  7. java gui可见即可得

    http://www.eclipse.org/windowbuilder/ http://download.eclipse.org/windowbuilder/WB/release/R20130927 ...

  8. 关于ligerUI中ligerTree代码中的一个bug,造成该控件无法通过url的POST方式加载数据

    该bug造成ligerTree参数中的method无论你怎么设置都只能用get方式提交 由于本人水平有限,只是找到原因,但无法修正 ligerUI v1.1.9 版本中的ligerui.all.js文 ...

  9. HOOK函数(一)——进程内HOOK

    什么是HOOK呢?其实很简单,HOOK就是对Windows消息进行拦截检查处理的一个函数.在Windows的消息机制中,当用户产生消息时,应用程序通过调用GetMessage函数取出消息,然后把消息放 ...

  10. Mac OS X 在Finder新建文本文件

    Automator 新建一个 Application添加一个动作 "Run AppleScript"代码如下 on run {input, parameters} tell app ...