Educational Codeforces Round 6 C. Pearls in a Row set
There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai.
Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type.
Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printfinstead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row.
The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl.
On the first line print integer k — the maximal number of segments in a partition of the row.
Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment.
Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type.
If there are several optimal solutions print any of them. You can print the segments in any order.
If there are no correct partitions of the row print the number "-1".
5
1 2 3 4 1
1
1 5
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = ; vector<pair<int,int > > ans;
map<int ,int > mp;
set<int > s;
int main() {
int x,n,l;
scanf("%d",&n);
l = ;
for(int i = ; i <= n; i++) {
scanf("%d",&x);
if(s.count(x)) {
ans.push_back(make_pair(l,i));
s.clear();mp.clear();
l = i+;
}
else {
mp[x] = i;
s.insert(x);
}
}
if(!ans.size()) puts("-1");
else {
printf("%d\n",ans.size());
if(ans[ans.size()-].second != n) ans[ans.size()-].second = n;
for(int i = ; i < ans.size(); i++) printf("%d %d\n",ans[i].first,ans[i].second);
} return ;
}
Educational Codeforces Round 6 C. Pearls in a Row set的更多相关文章
- Educational Codeforces Round 6 C. Pearls in a Row
		
Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
 - [Educational Codeforces Round 16]E. Generate a String
		
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
 - [Educational Codeforces Round 16]D. Two Arithmetic Progressions
		
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
 - [Educational Codeforces Round 16]C. Magic Odd Square
		
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
 - [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 ...
 - [Educational Codeforces Round 16]A. King Moves
		
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
 - Educational Codeforces Round 9
		
Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...
 - Educational Codeforces Round 37
		
Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...
 - 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 ...
 
随机推荐
- linux:共享内存
			
#include <sys/ipc.h> #include <sys/shm.h> #include <string.h> #include <stdio.h ...
 - 【翻译自mos文章】11.2.0.4及更高版本号的asm实例中MEMORY_TARGET 和 MEMORY_MAX_TARGET的默认值和最小值
			
[翻译自mos文章]11.2.0.4及更高版本号的asm实例中MEMORY_TARGET 和 MEMORY_MAX_TARGET的默认值和最小值 来源于: Default and Minimum ME ...
 - Directx Matrix.PerspectiveFovLH Matrix.PerspectiveFovRH的理解
			
该函数一个四个参数public static Matrix PerspectiveFovLH ( float fieldOfViewY, float aspectRatio, float znearP ...
 - SqlServer Function 实例
			
① sql server function 创建 这里使用一个计算年龄精确到分的function作为一个demo, create Function [dbo].[fn_GetAge] ( @BIRTH ...
 - C++头文件一览
			
C++头文件一览 C.传统 C++ #include <assert.h> 设定插入点#include <ctype.h> 字符处理#include <errno.h&g ...
 - css实战笔记(一):写网页前的reset工作
			
reset.css是每个html必备的样式,其中有各种元素属性清零的代码. 为什么要有reset.css 让各个浏览器的CSS样式有一个统一的基准,比如清除各个浏览器为元素自带的margin.padd ...
 - Obj文件和Bin文件
			
本文导读:在用visual studio 编程时,会看到项目文件中含有bin和obj这两个文件夹,那么这两个文件夹具体包含一些什么东西的,具体作用是什么? 一.Bin文件夹 1.用来保存项目生成后程序 ...
 - PHP单词表
			
输出语句printechovar_dumpprint_rprintf变量的操作unset预定义变量$_SERVER$_GET$_POST$_REQUEST$_COOKIE,$_SESSION 会话技术 ...
 - iOS 处理图片的一些小 Tip
			
UIImage 缓存是怎么回事? 通过 imageNamed 创建 UIImage 时,系统实际上只是在 Bundle 内查找到文件名,然后把这个文件名放到 UIImage 里返回,并没有进行实际的文 ...
 - 如何使用 GNOME Shell 扩展
			
如何使用 GNOME Shell 扩展 作者: Abhishek Prakash 译者: LCTT MjSeven | 2018-03-15 10:53 评论: 1 简介:这是一份详细指南,我将会 ...