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. -bash: ls: command not found

    在iMac下ls既然command not found,查找了下 原因:在设置环境变量时,编辑profile文件没有写正确,导致在命令行下 ls等命令不能够识别.解决方案: 直接在控制台下  expo ...

  2. 浅谈 Underscore.js 中 _.throttle 和 _.debounce 的差异

    Underscore.js是一个很精干的库,压缩后只有5.2KB.它提供了几十种函数式编程的方法,弥补了标准库的不足,大大方便了JavaScript的编程. 本文仅探讨Underscore.js的两个 ...

  3. 使用ThinkPHP框架高速开发站点(多图)

    使用ThinkPHP框架高速搭建站点 这一周一直忙于做实验室的站点,基本功能算是完毕了.比較有收获的是大概了解了ThinkPHP框架.写一些东西留作纪念吧.假设对于相同是Web方面新手的你有一丝丝帮助 ...

  4. Netty 5用户指南

    Netty是一个提供异步事件驱动的网络应用框架,用以快速开发高性能.高可靠性的网络服务器和客户端程序.换句话说,Netty是一个NIO框架,使用它可以简单快速地开发网络应用程序,比如客户端和服务端的协 ...

  5. modelsim脚本文件的编写

    第一章 ModelSim介 绍 本指南是为 ModelSim5.5f版本编写的,该版本运行于UNIX和Microsoft Windows 95/98/Me/NT/2000的操作系统环境中.本指南覆盖了 ...

  6. hdu 1563 Find your present!

    Find your present! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  7. 查询制定行数的数据(2)对了,mysql不能用top关键字

    采用嵌套查询的方式,倒序之后前10条 倒序之后前9条 采用嵌套查询的方式,倒序之后前10条 排正序之后从第一条开始弄十条数据 排正序之后从第一条开始弄九条数据 排正序之后从第十条开始弄十条数据 排正序 ...

  8. ScriptManager的用法

    资料中如实是说:       1, ScriptManager(脚本控制器)是asp.net ajax存在的基础. 2, 一个页面只允许有一个ScriptManager,并且放在其他ajax控件的前面 ...

  9. 在masterpage中添加对usercontrol的引用

    在masterpage中添加对usercontrol的引用的方式: <%@ Register Src="/_controltemplates/15/Excellent Employee ...

  10. Win10 10586 更新

    最近发现,电脑c盘突然少了许多,发现c盘多了个windowsBT文件夹,大概6个G,恩,win10 又推出更新了,版本10586. 不知道为啥,更新时win10 把原来的下载的删除了,大概出了什么错误 ...