B. Amr and The Large Array

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/558/problem/B

Description

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 Input

5
1 1 2 2 1

Sample Output

1 5

HINT

题意

要求找到一个区间,使得包含同样的数最多的最短的区间……

题意真是蛋疼,不过还好我第一次就读对了

题解:

我们直接对于每个数,统计这个数出现的次数,然后再记录仪下开始位置和结束位置,然后跑一法1e6的复杂度就吼了!

代码

#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std; struct node
{
int x,y,z;
};
node a[]; int main()
{
for(int i=;i<=;i++)
a[i].x=,a[i].y=-,a[i].z=;
int n;
scanf("%d",&n);
int ans=;
for(int i=;i<=n;i++)
{
int x;
scanf("%d",&x);
a[x].x=min(i,a[x].x);
a[x].y=max(i,a[x].y);
a[x].z++;
ans=max(ans,a[x].z);
}
int ans1=,ans2=;
for(int i=;i<=;i++)
{
if(a[i].z==ans)
{
if(ans2-ans1>a[i].y-a[i].x)
ans2=a[i].y,ans1=a[i].x;
}
}
cout<<ans1<<" "<<ans2<<endl;
}

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

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

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

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

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

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

  7. Codeforces Round #312 (Div. 2)

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

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

  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. FontMetrics ----- 绘制文本,获取文本高度

    Canvas 绘制文本时,使用FontMetrics对象,计算位置的坐标. public static class FontMetrics { /** * The maximum distance a ...

  2. Delphi 之前解析串口数据

    //串口接收数据procedure TfrmClientMain.Comm1ReceiveData(Sender: TObject; Buffer: Pointer; BufferLength: Wo ...

  3. 安装Sikulix

    1.sikulix可以在xp,win7,8,10 Mac 10.10.x 以及Linux/Unix 系统上安装 2.安装Java支持 3.下载sikulisetup1.1.0.jar(那里下前篇有介绍 ...

  4. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 select_from_list_by_value(self, locator, *values)

    def select_from_list_by_value(self, locator, *values): """Selects `*values` from list ...

  5. 2013年19个最棒的HTML5网站模板免费下载

    上次我们整理了14个HTML5奉献给大家下载了,今天我再给大家整理了19个2013最新的HTML5模板供有需要的朋友下载使用,它们涉及不同的行业的模板需求,支持手机设备,十分精美! 1. Affini ...

  6. dedecms list 判断 每隔3次输出内容

    {dede:list pagesize='12' runphp='yes'} [field:global name=autoindex runphp="yes"](@me%3==0 ...

  7. (转)PHP开发框架浅析

    开发框架的定义我没有找到很准确的描述,下面几句话基本概括了开发框架的的功能和用途 框架是一种应用程序的半成品: 框架就像是人的骨骼一样: 框架是一组可复用的组件: 框架是一个可复用的设计构件…… 简而 ...

  8. gem openssl 出错

    Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources 1. ...

  9. flex中文说明手册

    http://help.adobe.com/zh_CN/Flex/4.0/UsingFlashBuilder/WS6f97d7caa66ef6eb1e63e3d11b6c4d0d21-7f07.htm ...

  10. Jquery 等待ajax返回数据loading控件ShowLoading组件

    1.意义 开发项目中,前台的页面要发请求到服务器,服务器响应请求返回数据到前台,这段时间,有可能因为返回的数据量较大导致前台页面出现短暂性的等待,此时如果用户因不知情而乱点击有可能造成逻辑混乱,所以此 ...