题目链接:

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. SpringMVC:前台jsp页面和后台传值

    前台jsp页面和后台传值的几种方式: 不用SpringMVC自带的标签 前台---->后台,通过表单传递数据(): 1.jsp页面代码如下,  modelattribute 有没有都行 < ...

  2. Android 进程间通信——AIDL

    代码地址如下:http://www.demodashi.com/demo/12321.html 原文地址:http://blog.csdn.net/vnanyesheshou/article/deta ...

  3. 在Centos 7上安装配置 Apche Kafka 分布式消息系统集群

    Apache Kafka是一种颇受欢迎的分布式消息代理系统,旨在有效地处理大量的实时数据.Kafka集群不仅具有高度可扩展性和容错性,而且与其他消息代理(如ActiveMQ和RabbitMQ)相比,还 ...

  4. android位置布局

    fill_parent 设置一个构件的布局为fill_parent将强制性地使构件扩展,以填充布局单元内尽可能多的空间.这跟Windows控件的dockstyle属性大体一致.设置一个顶部布局或控件为 ...

  5. java操作pdf

    使用pdf模板生成pdf 1,工具 Adobe Acrobat X Pro 2,pom文件配置 <dependency> <groupId>com.itextpdf</g ...

  6. git是一种分布式代码管理工具,git通过树的形式记录文件的更改历史,比如: base'<--base<--A<--A' ^ | --- B<--B' 小米工程师常常需要寻找两个分支最近的分割点,即base.假设git 树是多叉树,请实现一个算法,计算git树上任意两点的最近分割点。 (假设git树节点数为n,用邻接矩阵的形式表示git树:字符串数组matrix包含n个字符串,每个字符串由字符'0

    // ConsoleApplication10.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream& ...

  7. PHP下最好用的富文本HTML过滤器:HTMLPurifier使用教程

    HTMLPurifier是我目前用过最好的PHP富文本HTML过滤器了,采用了白名单机制,有效杜绝了用户提交表单中的非法HTML标签,从而可以防止XSS攻击! HTMLPurifier项目地址:htt ...

  8. 关于Gradle和Gradle插件的问题

    一.   Gradle更新插件问题 当更新Andorid studio 的时候,你可能会接收到一条让你更新Gradle插件到最新版本的建议.在项目编译需要的基础上,你可以选择接受或者手动选择一个具体的 ...

  9. iOS文档预览功能教程

     本文转载至 http://blog.csdn.net/devday/article/details/6580444   文档iosuinavigationcontrollerextensionmic ...

  10. python 基础 7.2 时间格式的相互转换

    #/usr/bin/python #coding=utf-8 #@Time   :2017/11/9 8:55 #@Auther :liuzhenchuan #@File   :时间格式的相互转换.p ...