码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-07-26 00:23:03      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

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的,还有众数的概念,要不然容易写晕。。。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<algorithm>
 5 #include<queue>
 6 #include<cstring>
 7 #define PAU putchar(‘ ‘)
 8 #define ENT putchar(‘\n‘)
 9 using namespace std;
10 const int maxv=1000000+10,inf=-1u>>1;
11 inline int read(){
12     int x=0,sig=1;char ch=getchar();
13     while(!isdigit(ch)){if(ch==-)sig=-1;ch=getchar();}
14     while(isdigit(ch))x=10*x+ch-0,ch=getchar();
15     return x*=sig;
16 }
17 inline void write(int x){
18     if(x==0){putchar(0);return;}if(x<0)putchar(-),x=-x;
19     int len=0,buf[15];while(x)buf[len++]=x%10,x/=10;
20     for(int i=len-1;i>=0;i--)putchar(buf[i]+0);return;
21 }
22 int l[maxv],m[maxv];
23 void init(){
24     int n=read(),ans1,ans2;  
25     int mx=0,mi=inf;
26     for(int i=1;i<=n;i++){
27         int x=read();
28         if(!l[x])l[x]=i;m[x]++;
29         if(m[x]>mx){
30             mx=m[x];ans1=l[x];ans2=i;mi=ans2-ans1;  
31         }else if(m[x]==mx&&i-l[x]<mi){
32             ans1=l[x];ans2=i;mi=ans2-ans1;
33         }
34     }
35     write(ans1);PAU;write(ans2);
36     return;
37 }
38 void work(){
39     return;
40 }
41 void print(){
42     return;
43 }
44 int main(){init();work();print();return 0;}

 

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

标签:

原文地址:http://www.cnblogs.com/chxer/p/4676796.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!