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. jQuery实现Ajax

    jQuery.ajax([settings]) type:类型,“POST”或“GET”,默认为GET url:发送地址 data:连同请求发送到服务器的数据 dataType:预期服务器返回的数据类 ...

  2. Scrapy实战-新浪网分类资讯爬虫

    项目要求: 爬取新浪网导航页所有下所有大类.小类.小类里的子链接,以及子链接页面的新闻内容. 什么是Scrapy框架: Scrapy是用纯Python实现一个为了爬取网站数据.提取结构性数据而编写的应 ...

  3. django(django项目创建,数据库迁移)

    Django项目的创建与介绍 安装:pip3 install django==1.11 查看版本号:django-admin --version 新建项目: 1.切到目标目录 2.django-adm ...

  4. php(ajax)异步刷新(转)

    第一种方法,ajax实现:当然,ajax使用起来确实很简单就可以实现,但是里面的很多知识还是比较有点深的.我之前做页面时间自动刷新的功能就是用的ajax.完整代码是:1.getTime.php: 复制 ...

  5. sql server中的数据类型转换函数

    1.cast(字段名 as varchar(40)) 2.convert(varchar(50),字段名)  日期转换: CONVERT(varchar(20), GETDATE(),120)

  6. BZOJ 1015: [JSOI2008]星球大战starwar【并查集】

    题目可以表述成:给定一个无向图G,每次删除它的一个点和与点相关的边集,每次询问该操作后图G的连通度(连通分量的个数).和上一题一样都是考察逆向思维,虽然删除点的做法不会,但是每次加点后询问连通度却是并 ...

  7. bzoj1064【Noi2008】假面舞会

    题意:http://www.lydsy.com/JudgeOnline/problem.php?id=1064 给一个有向图染色,每个点的后继必须相同,问至少&至多有多少种染色方案 sol: ...

  8. java面试题之能创建volatile数组吗?

    答:能,只不过只是一个指向数组的引用,而不是整个数组,如果改变了引用指向的数组,将会受到volatile的保护,但是如果多个线程同时改变数组的元素,volatile关键字就不能起到保护的作用.

  9. 如何将文件上传到ftp

    方法1(推荐,炒鸡简单):双击我的电脑,在地址栏里输入你的ftp地址回车(比如: ftp://220.103.86.96),然后会弹出一个输入登录账号和密码的对话框,输入你的ftp账号和密码回车便进入 ...

  10. ZOJ - 3816 Generalized Palindromic Number dfs

    Generalized Palindromic Number Time Limit: 2 Seconds                                     Memory Limi ...