Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.

Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.

Help Amr by choosing the smallest subsegment possible.

Input

The first line contains one number n (1 ≤ n ≤ 105), the size of the array.

The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.

Output

Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.

If there are several possible answers you may output any of them.

Sample test(s)
input
5
1 1 2 2 1
output
1 5
input
5
1 2 2 3 1
output
2 3
input
6
1 2 2 1 1 2
output
1 5
Note

A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1

题解:一眼DP,记录一下尾巴就好,要记住窝萌的算法是Online的,还有众数的概念,要不然容易写晕。。。

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstring>
#define PAU putchar(' ')
#define ENT putchar('\n')
using namespace std;
const int maxv=+,inf=-1u>>;
inline int read(){
int x=,sig=;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')sig=-;ch=getchar();}
while(isdigit(ch))x=*x+ch-'',ch=getchar();
return x*=sig;
}
inline void write(int x){
if(x==){putchar('');return;}if(x<)putchar('-'),x=-x;
int len=,buf[];while(x)buf[len++]=x%,x/=;
for(int i=len-;i>=;i--)putchar(buf[i]+'');return;
}
int l[maxv],m[maxv];
void init(){
int n=read(),ans1,ans2;
int mx=,mi=inf;
for(int i=;i<=n;i++){
int x=read();
if(!l[x])l[x]=i;m[x]++;
if(m[x]>mx){
mx=m[x];ans1=l[x];ans2=i;mi=ans2-ans1;
}else if(m[x]==mx&&i-l[x]<mi){
ans1=l[x];ans2=i;mi=ans2-ans1;
}
}
write(ans1);PAU;write(ans2);
return;
}
void work(){
return;
}
void print(){
return;
}
int main(){init();work();print();return ;}

Codeforces Round #312 (Div. 2) B.Amr and The Large Array的更多相关文章

  1. Codeforces Round #312 (Div. 2)B. Amr and The Large Array 暴力

    B. Amr and The Large Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  2. Codeforces Round #312 (Div. 2) C. Amr and Chemistry 暴力

    C. Amr and Chemistry Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/558/ ...

  3. Codeforces Round #312 (Div. 2) C.Amr and Chemistry

    Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experime ...

  4. B. Amr and The Large Array(Codeforces Round #312 (Div. 2)+找出现次数最多且区间最小)

    B. Amr and The Large Array time limit per test 1 second memory limit per test 256 megabytes input st ...

  5. Codeforces Round #312 (Div. 2) ABC题解

    [比赛链接]click here~~ A. Lala Land and Apple Trees: [题意]: AMR住在拉拉土地. 拉拉土地是一个很漂亮的国家,位于坐标线.拉拉土地是与著名的苹果树越来 ...

  6. Codeforces Round #312 (Div. 2)

    好吧,再一次被水题虐了. A. Lala Land and Apple Trees 敲码小技巧:故意添加两个苹果树(-1000000000, 0)和(1000000000, 0)(前者是位置,后者是价 ...

  7. C. Amr and Chemistry(Codeforces Round #312 (Div. 2) 二进制+暴力)

    C. Amr and Chemistry time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. Codeforces Round #312 (Div. 2) A. Lala Land and Apple Trees 暴力

    A. Lala Land and Apple Trees Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/cont ...

  9. Codeforces Round #312 (Div. 2) A.Lala Land and Apple Trees

    Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. ...

随机推荐

  1. [转] [翻译]图解boost::bind

    http://kelvinh.github.io/blog/2013/12/03/boost-bind-illustrated/ 其实这是很久之前留的一个坑了,一直没有填.. 记得在刚开始看到 boo ...

  2. Java基础知识强化之集合框架笔记05:Collection集合的遍历

    1.Collection集合的遍历 Collection集合直接是不能遍历的,所以我们要间接方式才能遍历,我们知道数组Array方便实现变量,我们可以这样: 使用Object[]  toArray() ...

  3. HTML基础语句

    一,网页基础结构: 1 <html> 2 <head> 3 <title>我的第一个网页</title> 4 </head> 5 <b ...

  4. DEDECMS批量修改默认文章和列表命名规则的方法

    很多人因为添加分类而苦恼,尤其是批量添加的时候,必须要重新修改一下文章命名规则和列表命名规则,都是为了做SEO.如果进行默认值的修改,就会事半功倍.不多说. 一.DEDE5.5修改默认文章命名规则. ...

  5. KNN(k-nearest-neighbor)算法

    一.算法概述 该方法的思路是:如果一个样本在特征空间中的k个最相似(即特征空间中最邻近)的样本中的大多数属于某一个类别,则该样本也属于这个类别.KNN算法中, 所选择的邻居都是已经正确分类的对象(训练 ...

  6. 【USACO 1.5.2】回文质数

    [题目描述] 因为151既是一个质数又是一个回文数(从左到右和从右到左是看一样的),所以 151 是回文质数. 写一个程序来找出范围[a,b](5 <= a < b <= 100,0 ...

  7. ORA-00933 UNION 与 ORDER BY

    原文:http://blog.csdn.net/lwei_998/article/details/6093807 The UNION operator returns only distinct ro ...

  8. mybatis中association的column传入多个参数值

    顾名思义,association是联合查询. 在使用association中一定要注意几个问题.文笔不好,白话文描述一下. 1: <association property="fncg ...

  9. eval("("+json对象+")")

    var obj=eval("("+data+")"); 看看下面这条,应该能想到json的数据结构“+(json对象名)+”由于json是以”{}”的方式来开始 ...

  10. python 安装PyV8 和 lxml

    近来在玩python爬虫,需要使用PyV8模块和lxml模块.但是执行pip install xx 或者easy_install xx 指令都会提示一些错误.这些错误有些是提示pip版本过低或者缺少v ...