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. node.js----服务器http

    请求网址过程: 1.用户通过浏览器发送一个http的请求到指定的主机 2.服务器接收到该请求,对该请求进行分析和处理 3.服务器处理完成以后,返回对应的数据到用户机器 4.浏览器接收服务器返回的数据, ...

  2. (转)iOS开发之Pch预编译文件的创建

    本文转自 http://www.cnblogs.com/496668219long/p/4568265.html 在Xcode6之前,创建一个新工程xcode会在Supporting files文件夹 ...

  3. WIN10配置MAVEN

    添加新的系统环境变量M2_HOME, 并设置其值为你安装的目录MAVEN_HOME=D:\Softwares\apache-maven-3.2.2. 更新系统PATH 变量, 添加;%M2_HOME% ...

  4. python中datetime模块中datetime对象的使用方法

    本文只讲述datetime模块中datetime对象的一些常用的方法,如果读者需要更多datetime模块的信息,请查阅此文档. datetime模块的对象有如下: timedelta date da ...

  5. PAT Basic 1059

    1059 C语言竞赛 C 语言竞赛是浙江大学计算机学院主持的一个欢乐的竞赛.既然竞赛主旨是为了好玩,颁奖规则也就制定得很滑稽: 0.冠军将赢得一份“神秘大奖”(比如很巨大的一本学生研究论文集……). ...

  6. Java面试之基础题---对象Object

    参数传递:Java支持两种数据类型:基本数据类型和引用数据类型. 原始数据类型是一个简单的数据结构,它只有一个与之相关的值.引用数据类型是一个复杂的数据结构,它表示一个对象.原始数据类型的变量将该值直 ...

  7. luogu2634 聪聪可可

    点分治裸题 #include <iostream> #include <cstdio> using namespace std; int n, uu, vv, ww, ans, ...

  8. bean容器能力

    bean容器能力 对bean容器的最简单的述求 能生产bean 能注入组装bean: 字段,构造函数 spring bean容器(3.0版本)的能力列表 能生产bean 能注入组装bean:字段,构造 ...

  9. 三、harbor部署之SSL

    1 签名证书与自签名证书 签名证书:由权威颁发机构颁发给服务器或者个人用于证明自己身份的东西. 自签名证书:由服务器自己颁发给自己,用于证明自己身份的东西,非权威颁发机构发布. 2 openssl简介 ...

  10. 【LeetCode】Combination Sum II(组合总和 II)

    这道题是LeetCode里的第40道题. 题目要求: 给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合. can ...