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. Php 笔记4-----php 细节知识

    从 php5开始  php.ini  register_globals参数为OFF  ,禁止全局变量. 以前的情况下,  全局变量是默认为On的 , 所以,浏览器的表单中控件,会自动根据name在服务 ...

  2. ansible命令执行模块使用

    ansible命令执行模块使用 1.命令执行模块-command 在远程节点上运行命令. 命令模块使用命令名称,接上空格-的分割符作为参数使用,但是不支持管道符和变量等,如果要使用这些,那么可以使用s ...

  3. 黑马程序员——有关protocol代理模式的举例说明

    学习了protocol协议的基本原理和使用方法之后 ,下面就看一下在程序中是怎么体现这种代理思想的. 假定有个人jack需要找一个厨师为自己做饭,当他想要吃饭的时候就可以让厨师给他做好饭.这一需求如何 ...

  4. kali2 vmtools

    root@kali:~# cat /etc/apt/sources.list# Regular Repositoriesdeb http://http.kali.org/kali sana main ...

  5. How To Set Up Port Forwarding in Linux

    Port forwarding usually used when we want our computer act like a router. Our computer receive the p ...

  6. windows7__32位下安装python2.6.6

    1.下载windows7__32位的python2.6.6.mis文件,直接运行.默认安装即可 2.设置系统环境变量,目的在cmd下能敲python后能够自动调用到安装目录程序 设计如下:(我的电脑- ...

  7. 为operamasks增加HTML扩展方式的组件调用

    #为operamasks增加HTML扩展方式的组件调用 ##背景 之前的[博文](http://www.cnblogs.com/p2227/p/3540858.html)中有提及到,发现easyui中 ...

  8. Chapter 6 Windows下编译pycaffe

    pycaffe 是 Caffe 提供的Python接口,我们知道 Caffe 的整个framework是基于C Plus Plus 来开发的,所以pycaffe 的根本就是提供Python调用Caff ...

  9. c#装B指南

    要想让自己的代码,看起来更优雅,更有逼格,更高大上,就一定要写出晦涩难懂,而又简洁的代码来. 对于类自身的全局变量,一定要加this,对于基类的,一定要加base.反射不要多,但一定要有,而且偶尔就来 ...

  10. ajax 加载不同数据

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...