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


Amr has got a large array of sizen. 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 numbern(1 ≤ n ≤ 105), the size of the array.

The second line containsnintegersai(1 ≤ ai ≤ 106), representing elements of the array.

Output

Output two integersl, 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 subsegmentBof an arrayAfromltoris an array of sizer - l + 1whereBi = Al + i - 1for all1 ≤ 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;}

优质内容筛选与推荐>>
1、记录从裸机到TensorFlow GPU版运行 的配置过程
2、在Flex控件中使用XMLListCollection
3、JavaScript基础
4、apt-update 更新失败 (无法连接到ubuntu服务器)
5、windows,linux,cmd查看公网/外网IP


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号





    联系我们

    欢迎来到TinyMind。

    关于TinyMind的内容或商务合作、网站建议,举报不良信息等均可联系我们。

    TinyMind客服邮箱:support@tinymind.net.cn