B. Amr and The Large Array
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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


对每一个可能值计数

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (2000000+10)
#define N (1000000)
typedef long long ll;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int l[MAXN],r[MAXN],t[MAXN],n;
int main()
{
// freopen("B.in","r",stdin);
// freopen(".out","w",stdout); For(i,N) l[i]=INF,r[i]=-INF,t[i]=0; cin>>n;
For(i,n)
{
int p;scanf("%d",&p);
l[p]=min(l[p],i);
r[p]=max(r[p],i);
t[p]++;
} int ma=0,ans=INF,j=0;
For(i,N) ma=max(ma,t[i]);
For(i,N)
if (ma==t[i]&&ans>r[i]-l[i]+1)
{
ans=r[i]-l[i]+1;j=i;
}
cout<<l[j]<<' '<<r[j]<<endl; return 0;
}

CF 558B(Amr and The Large Array-计数)的更多相关文章

  1. Codeforces 558B Amr and The Large Array

    B. Amr and The Large Array time limit per test 1 second memory limit per test 256 megabytes input st ...

  2. codeforces 558B. Amr and The Large Array 解题报告

    题目链接:http://codeforces.com/problemset/problem/558/B 题目意思:给出一个序列,然后找出出现次数最多,但区间占用长度最短的区间左右值. 由于是边读入边比 ...

  3. codeforces 558B B. Amr and The Large Array(水题)

    题目链接: B. Amr and The Large Array time limit per test 1 second memory limit per test 256 megabytes in ...

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

    B. Amr and The Large Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  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. 【36.86%】【codeforces 558B】Amr and The Large Array

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

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

  8. codeforces 558B Amr and The Large Array-yy

    题意:有一个数组.如今要削减它的尺寸.数组中同样元素的个数的最大值为数组的魅力值,要求削减后魅力值不能降低,同一时候要尽可能的把尺寸减到最小 分析:水题,主要是不要想复杂了.还有就是沉下心来做 代码: ...

  9. CF 1006C Three Parts of the Array【双指针/前缀和/后缀和/二分】

    You are given an array d1,d2,-,dn consisting of n integer numbers. Your task is to split this array ...

随机推荐

  1. kafka异常问题汇总

    1.报错:: java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.NotLeaderForPartition ...

  2. AWK原理及命令和文件输入

    一.awk简介  1.awk是3个姓氏的首字母,代表该语言的3个作者,awk的版本有很多,包括:旧版awk,新版awk(nawk),GNU awk(gawk)等.    awk程序有awk命令,括在引 ...

  3. 10大vim插件

    Taglist taglist是一个用于显示定位程序中各种符号的插件,例如宏定义.变量名.结构名.函数名这些东西 我们将其称之为符号(symbols),而在taglist中将其称之为tag.显然,要想 ...

  4. hdu2084

    老题目了 #include <stdio.h> int main(){ ][]; int i,j,max; int c,n; scanf("%d",&c); w ...

  5. HDU1007 TLE代码和AC代码对比

    这题卡了一天,上午开始看算法导论,然后实现了,一开始是wa,后来TLE,由于我开始的实现方式比较笨,而且在递归调用的时候很是混乱,用了好多数组.导致我的代码不断的出问题.具体是算法导论33-4. 后来 ...

  6. 九度oj 题目1051:数字阶梯求和

    题目描述: 给定a和n,计算a+aa+aaa+a...a(n个a)的和. 输入: 测试数据有多组,输入a,n(1<=a<=9,1<=n<=100). 输出: 对于每组输入,请输 ...

  7. 【bzoj1174】[Balkan2007]Toponyms Trie树

    题目描述 给你一个字符集合,你从其中找出一些字符串出来. 希望你找出来的这些字符串的最长公共前缀*字符串的总个数最大化. 输入 第一行给出数字N.N在[2,1000000] 下面N行描述这些字符串,长 ...

  8. 【bzoj3489】A simple rmq problem 三维KD-tree

    题目描述 因为是OJ上的题,就简单点好了.给出一个长度为n的序列,给出M个询问:在[l,r]之间找到一个在这个区间里只出现过一次的数,并且要求找的这个数尽可能大.如果找不到这样的数,则直接输出0.我会 ...

  9. 【bzoj4383】[POI2015]Pustynia 线段树优化建图+差分约束系统+拓扑排序

    题目描述 给定一个长度为n的正整数序列a,每个数都在1到10^9范围内,告诉你其中s个数,并给出m条信息,每条信息包含三个数l,r,k以及接下来k个正整数,表示a[l],a[l+1],...,a[r- ...

  10. Spring Cloud 从入门到精通

    Spring Cloud 是一套完整的微服务解决方案,基于 Spring Boot 框架,准确的说,它不是一个框架,而是一个大的容器,它将市面上较好的微服务框架集成进来,从而简化了开发者的代码量. 本 ...