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

#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. 打不开BT,一直重复的关闭开启。

    /bt-btif (25335): ...preload_wait_timeout (retried:0/max-retry:1)...D/bt_userial(25335): RX terminat ...

  2. boost ASIO实例

    client端代码 #include <iostream> #include <boost/asio.hpp> #include <boost/bind.hpp> ...

  3. 转:12C CDB and pdb with sql developer

    How to install the 12c DB and use the Pluggable DB with SQL DeveloperGoal To give a path to install ...

  4. 8.1 sikuli报错: 提示没有对应的javaw

    对于sikuli,需要安装32位的jdk且不能高于1.7的版本. 对于64位系统的C盘,Program Files文件夹是64位的,Program File(x86)文件夹是32位的 需要安装一个32 ...

  5. Haproxy的安装和配置示例

    1.ha proxy简介ha proxy是一个开源的,高性能的,基于tcp第四层和http第七层应用的负载均衡软件优点:可靠性和稳定性非常好          最高可以同时维护40000-50000个 ...

  6. Tree Cutting

    Tree Cutting Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/131072 K (Java/Others) Prob ...

  7. WPF Template模版之寻找失落的控件【三】

    “井水不犯河水”常用来形容两个组织之间界限分明.互不相干,LogicTree与控件内部这颗小树之间就保持着这种关系.换句话说,如果UI元素树上有个X:Name=“TextBox1”的控件,某个控件内部 ...

  8. 【转】关于C execlp函数的理解

    转自:http://bachue.is-programmer.com/posts/21611.html execlp(从PATH 环境变量中查找文件并执行) 相关函数 fork,execl,execl ...

  9. oracle的row_number()和rownum

    row_number() 函数和rownum的介绍: 1.row_number() 方法的格式: row_number()over([partition by col1] order by col2) ...

  10. linux的学习系列 8---进程管理

    当我们运行程序时,Linux会为程序创建一个特殊的环境,该环境包含程序运行需要的所有资源,以保证程序能够独立运行,不受其他程序的干扰.这个特殊的环境就称为进程. 每个 Linux 命令都与系统中的程序 ...