Codeforce 3B. 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.

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

题意:
Amr只追求一串数的美丽度,所谓美丽度,在题目中被定义为数串中某个元素的最多出现次数,现在让你缩小串的长度,但保持美丽度不变,问缩小后串的开始和结束位置。
分析:
是道模拟,先统计美丽度,再遍历数串,一开始提交的代码总是显示compilation error,原因是所申请的内存空间太大。

CE code:

#include<cstdio>
#include<iostream>
#include<cmath>
#include<map>
//#include<bits/stdc++.h>
#include<istream>
#include<string>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
bool flag1;
int a[1000000];
int num[1000000]={1},m[1000000]={1};
int s[20500][20500]={0,0};
struct x
{
    int ii,jj;
}node[10000];
bool cmp(x a,x b)
{
	return a.jj<b.jj;
}

int main()
{
    int n,k=1,max=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
           if(a[i])
           {
               num[a[i]]++;//1 1 2 2 1
           }
    }
    for(int i=1;i<=n;i++)
    {
        if(max<num[a[i]]) max=num[a[i]];
    }
    bool flag;
    int h=1;
    for(int i=1;i<=n;i++)
    {
		k=1;
        for(int j=i+1;j<=n;j++)
        {
            if(a[i]==a[j]) k++;
            if(k==max)
            {
                 flag=1;
                 s[i][j]=1;
				 h++;
                 break;
            }
        }
       // if(flag) break;
    }
	int minn=0;
	int f=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(s[i][j]==1)
			{
				 node[f].ii=i;
				 node[f].jj=j-i;
				f++;

		    }
	     }
	}
	sort(node+1,node+f,cmp);
	cout<<node[1].ii<<" "<<node[1].ii+node[1].jj;
}

猜你喜欢

转载自blog.csdn.net/weixin_43238423/article/details/90668798