水题,每当出现重复就分割开来,最后留下的尾巴给最后一段

#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<vector>
#include<map>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std; const int maxn=*+;
map<int,int>m;
int n;
int a[maxn];
struct X
{
int l,r;
};
vector<X>ans; int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
m.clear();
int FinalRight=-;
int left=,right=;
for(int i=;i<=n;i++)
{
if(m[a[i]]==)
{
m.clear();
FinalRight=i;
X seg;
seg.l=left;
seg.r=i;
ans.push_back(seg);
left=i+;
}
else
{
m[a[i]]=;
right=i;
}
}
if(ans.size()==) printf("-1\n");
else
{
ans[ans.size()-].r=n;
printf("%d\n",ans.size());
for(int i=;i<ans.size();i++)
printf("%d %d\n",ans[i].l,ans[i].r);
}
return ;
}

CodeForces 620C Pearls in a Row的更多相关文章

  1. CodeForces - 620C Pearls in a Row 贪心 STL

    C. Pearls in a Row time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. codeforces C. Pearls in a Row map的应用

    C. Pearls in a Row time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. cf 620C Pearls in a Row(贪心)

    d.有一串数字,要把这些数字分成若干连续的段,每段必须至少包含2个相同的数字,怎么分才能分的段数最多? 比如 是1 2 1 3 1 2 1 那么 答案是 21 34 7 即最多分在2段,第一段是1~3 ...

  4. Codeforces 620C EDU C.Pearls in a Row ( set + greed )

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

  5. 【32.26%】【codeforces 620C】Pearls in a Row

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

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

    Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...

  7. 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 ...

  8. C. Pearls in a Row

    C. Pearls in a Row time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. CF620C Pearls in a Row

    CF620C Pearls in a Row 洛谷评测传送门 题目描述 There are nn pearls in a row. Let's enumerate them with integers ...

随机推荐

  1. MongoDB用户

    MongoDB  增加用户 删除用户  修改用户  读写权限 只读权限,   MongoDB用户权限分配的操作是针对某个库来说的.--这句话很重要.   1. 进入ljc 数据库:       use ...

  2. 多说【最近访客】JS插件通用代码使用方法

    多说[最近访客]JS插件可以显示近期访问过你的博客并且已经使用向多说授权过的社交网络账号登录的用户头像,效果如下图所示. 最近访客JS插件的添加步骤如下: 1. 添加多说公用JS代码,每个页面只需添加 ...

  3. nextSibling,previousSibling,childNodes常见错误

    在使用nextSibling与previousSibling时,常出现选不到预计对象的情况 eg: <div class="a">1</div> <d ...

  4. Hidden Word

    Hidden Word time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  5. AI 人工智能 探索 (二)

    完整被动技能代码 using UnityEngine; using System.Collections; public class AI : MonoBehaviour { private Hash ...

  6. elasticsearch 索引优化

    ES索引优化篇主要从两个方面解决问题,一是索引数据过程:二是检索过程.  索引数据过程我在上面几篇文章中有提到怎么创建索引和导入数据,但是大家可能会遇到索引数据比较慢的过程.其实明白索引的原理就可以有 ...

  7. stray '/241' in program 错误

    意思是c/c++中的编译错误. 该错误是指源程序中有非法字符,需要去掉非法字符.一般是由于从别的地方粘贴过来造成的. 方法:1.把所粘的文字放到记事本里就行了 2.把出错行的空格删掉重新打一下试试.

  8. ubuntu server 11.10 mysql 自动备份脚本

    1.下载最新的备份脚本(AutoMySQLBackup) 点这里下载 2.修改脚本配置部分 vi  /root/automysqlbackup-2.5.1-01.sh USERNAME=root PA ...

  9. MySQL常用命令总结2

    USE db_name; //使用(打开)数据库 SELECT DATABASE(); //查看当前打开的数据库 CREATE TABLE tb_name( column_name data_type ...

  10. zencart hosts本地解析

    C:\WINDOWS\system32\drivers\etc\hosts 127.0.0.1  www.aberc220.com   别人 192.168.1.64 www.aberc220.com ...