题目链接:

B. Amr and The Large Array

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

 

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.

Examples
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

题意:

使数组的魅力值保持相同,但数组的长度尽量小;

思路:

用vector的大小来看是否对应魅力值的那个数,而vector保存了这个数的各个位置,可以得到长度,一半比较一边更新就好;

AC代码:

/*
2014300227 558B - 9 GNU C++11 Accepted 61 ms 15728 KB
*/
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+;
typedef long long ll;
const double PI=acos(-1.0);
int n,a[N];
vector<int>ve[*N];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
ve[a[i]].push_back(i);
}
int ans=,l=,r=;
for(int i=;i<=1e6;i++)
{
int g=ve[i].size();
if(g){
if(g>ve[ans].size())
{
int len=g;
l=ve[i][];
r=ve[i][len-];
ans=i;
}
else if(g==ve[ans].size())
{
int s=g;
if(ve[i][s-]-ve[i][]<r-l)
{
l=ve[i][];
r=ve[i][s-];
ans=i;
}
}
}
}
cout<<l<<" "<<r<<endl; return ;
}

codeforces 558B B. Amr and The Large Array(水题)的更多相关文章

  1. 【36.86%】【codeforces 558B】Amr and The Large Array

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  2. Codeforces 558B Amr and The Large Array

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

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

  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) B.Amr and The Large Array

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

  6. CF451B Sort the Array 水题

    Codeforces Round #258 (Div. 2) Sort the Array B. Sort the Array time limit per test 1 second memory ...

  7. codeforces 14A - Letter & codeforces 859B - Lazy Security Guard - [周赛水题]

    就像title说的,是昨天(2017/9/17)周赛的两道水题…… 题目链接:http://codeforces.com/problemset/problem/14/A time limit per ...

  8. Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题

    A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...

  9. Codeforces Round #115 B. Plane of Tanks: Pro 水题

    B. Plane of Tanks: Pro Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/17 ...

随机推荐

  1. .net 网站登录

    如何实现,按回车键,自动登录,在相应控件上添加onkeypress事件 function CheckCodePress(e){ var e = e||window.event if (e.keyCod ...

  2. cocos2dx-3.0(8)------Label、LabelTTF、LabelAtlas、LabelBMFont使用之法

    ----我的生活,我的点点滴滴!! 最后一个LabelBMFont了,字体图集LabelBMFont,LabelBMFont类是一个基于位图的字体图集.是一个包括全部你须要于坐标数据一起显示在屏幕上的 ...

  3. myql5.7.7优化配置參数

    # Other default tuning values # MySQL Server Instance Configuration File # ------------------------- ...

  4. android开发系列之使用xml自定义控件

    在android开发的过程中,有的时候面对多个Activity里面一些相同的布局,我们需要写多次相同的代码,同时这种方法给我们的项目维护也带来了很大不便.那么有没有一种可行的办法能够将Activity ...

  5. 把对象写入Postgresql中

    工作中,遇到把大对象写入Postgresql数据库中 package com.geni_sage.gdme.cws.dic; import java.io.BufferedInputStream; i ...

  6. Github的基本功能:

    作者:Fadeoc Khaos链接:http://www.zhihu.com/question/20070065/answer/30521531来源:知乎著作权归作者所有,转载请联系作者获得授权. G ...

  7. [Linux] 网络

    如何在网络中标识一台计算机 IP 多个程序如何不冲突 通信端口 不同的计算机如何通信 协议 IP A类:0+7位网络号+24位主机号,可用网络2^7-2个,每个网络可容纳2^24-2个主机 B类:10 ...

  8. 中面试中你不可回避的C、C++的问题(一)

    基础中的基础 局部变量与全局变量问题 (使用’ ::’) 2.      如何在另个文件中引用一个全局变量 (extern) 3.      全局变量可以定义被多个C文件包含,并且是static 4. ...

  9. C# C/S程序使用HTML文件作为打印模板

    C#   C/S程序使用HTML文件作为打印模板 在网上找了一堆的资料,整理到郁闷呀,慢慢试慢慢改.哎,最终成功了,哈,菜鸟伤不起呀 public partial class Print : Form ...

  10. python发布IIS

    参考文档 https://segmentfault.com/a/1190000008909201 http://blog.51cto.com/anngle/1922041 https://www.cn ...