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

#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. http get with body data

    http://stackoverflow.com/questions/978061/http-get-with-request-body Yes, you can send a request bod ...

  2. windowSoftInputMode键盘把输入框挡住了

    android:windowSoftInputMode="stateHidden|adjustResize" >

  3. SQL 优化案例 1

    create or replace procedure SP_GET_NEWEST_CAPTCHA( v_ACCOUNT_ID in VARCHAR2, --接收短信的手机号 v_Tail_num i ...

  4. One-Way Reform

    One-Way Reform time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  5. html5利用websocket完成的推送功能

    利用websocket和java完成的消息推送功能,服务器用的是tomcat7.0,一些东西是自己琢磨的,也不知道恰不恰当,不恰当处,还请各位见谅,并指出. 程序简单来说,就是客户A可以发送消息给客户 ...

  6. Android摄像头:只拍摄SurfaceView预览界面特定区域内容(矩形框)---完整(原理:底层SurfaceView+上层绘制ImageView)

    Android摄像头:只拍摄SurfaceView预览界面特定区域内容(矩形框)---完整实现(原理:底层SurfaceView+上层绘制ImageView) 分类: Android开发 Androi ...

  7. 网络摄像头Androi端显示(mjpeg)源码分析

    main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:and ...

  8. Linux添加系统环境变量的两种方法

    方法一 export PATH=/usr/local/bin:$PATH 这种方法的PATH 在终端关闭 后就会消失.所以还是建议通过编辑/etc/profile来改PATH 方法二 # vim /e ...

  9. Binary Watch

    Binary Watch 描述 Consider a binary watch with 5 binary digits to display hours (00 - 23) and 6 binary ...

  10. oracle数据库查询常用语句

    1.查询SCOTT表中有多少表,并显示表的一些描述select * from all_tables WHERE owner='SCOTT' ; 2.查询oracle数据库版本select * from ...