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<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h> #define N 1000001 using namespace std; int n,m; struct node
{
int x;
int y;
int ans;
int cnt;
}q[1000100]; bool cmp(node a,node b)
{
if(a.cnt == b.cnt)
{
return a.ans < b.ans;
}
return a.cnt > b.cnt;
} int main()
{
while(scanf("%d",&n)!=EOF)
{
int mm;
for(int i=0;i<=N;i++)
{
q[i].cnt = 0;
}
int maxx = 0;
int a;
for(int i=1;i<=n;i++)
{
scanf("%d",&a);
if(mm<a)
{
mm = a;
}
if(q[a].cnt == 0)
{
q[a].x = i;
q[a].y = i;
q[a].ans = 0;
q[a].cnt++;
}
else
{
q[a].cnt++;
q[a].y = i;
q[a].ans = q[a].y - q[a].x;
}
if(maxx<q[a].cnt)
{
maxx = q[a].cnt;
}
}
sort(q,q+N,cmp);
printf("%d %d\n",q[0].x,q[0].y); }
return 0;
}

B. Amr and The Large Array(Codeforces Round #312 (Div. 2)+找出现次数最多且区间最小)的更多相关文章

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

  2. Codeforces Round #312 (Div. 2) ABC题解

    [比赛链接]click here~~ A. Lala Land and Apple Trees: [题意]: AMR住在拉拉土地. 拉拉土地是一个很漂亮的国家,位于坐标线.拉拉土地是与著名的苹果树越来 ...

  3. Codeforces Round #312 (Div. 2)

    好吧,再一次被水题虐了. A. Lala Land and Apple Trees 敲码小技巧:故意添加两个苹果树(-1000000000, 0)和(1000000000, 0)(前者是位置,后者是价 ...

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

  5. Codeforces Round #390 (Div. 2) D. Fedor and coupons(区间最大交集+优先队列)

    http://codeforces.com/contest/754/problem/D 题意: 给定几组区间,找k组区间,使得它们的公共交集最大. 思路: 在k组区间中,它们的公共交集=k组区间中右端 ...

  6. Codeforces Round #312 (Div. 2) C. Amr and Chemistry 暴力

    C. Amr and Chemistry Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/558/ ...

  7. Codeforces Round #312 (Div. 2) C.Amr and Chemistry

    Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experime ...

  8. C. Amr and Chemistry(Codeforces Round #312 (Div. 2) 二进制+暴力)

    C. Amr and Chemistry time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. codeforces 1042d//Petya and Array// Codeforces Round #510 (Div. 2)

    题意:给出一个数组,求其中和小于t的区间数. 先计算前缀和数组sum[i].对当前的sum[i],查询树状数组中有几个比(sum[i]-t)大的数,那么用sum[i]减它就是一个合法区间.再将当前的s ...

随机推荐

  1. 第3节 mapreduce高级:2、3、课程大纲&共同好友求取步骤一、二

    第五天课程大纲:1.社交粉丝的数据分析:求共同好友2.倒排索引的建立3.自定义inputFormat合并小文件 4.自定义outputformat5.分组求topN6.MapReduce的其他补充 了 ...

  2. 从C#程序中调用非受管DLLs

    从C#程序中调用非受管DLLs 文章概要: 众所周知,.NET已经渐渐成为一种技术时尚,那么C#很自然也成为一种编程时尚.如何利用浩如烟海的Win32 API以及以前所编写的 Win32 代码已经成为 ...

  3. hdu 1792 A New Change Problem(互质数之间最大不能组合数和不能组合数的个数)

    题意:求互质的m和n的最大不能组合数和不能组合数的个数 思路:m和n的最大不能组合数为m*n-m-n,不能组合数的个数为(m-1)*(n-1)/2 推导: 先讨论最大不能组合数 因为gcd(m,n)= ...

  4. CSU 2018年12月月赛 D 2216 : Words Transformation

    Description There are n words, you have to turn them into plural form. If a singular noun ends with ...

  5. poj3134 Power Calculus

    题目描述: 你现在有x^1,每动一步可以用当前存在的x^a和x^b获得x^(a+b)或x^(abs(a-b)).给出n(n<=1000),求最少多少步能得到x^n. 题解: IDDFS.枚举步数 ...

  6. Bash的循环结构(for和while)

    在bash有三中类型的循环结构表达方法:for,while,until.这里介绍常用的两种:for和while. for bash的for循环表达式和python的for循环表达式风格很像: for ...

  7. Ubuntu中Python3虚拟环境的搭建

    1.环境准备 首先请自行安装好Python3和pip3(一般Ubuntu是自带Python3的,可以通过sudo apt-get install python3-pip命令来安装pip3) 安装完成后 ...

  8. POJ-3041 Asteroids,二分匹配解决棋盘问题。

    Asteroids Time Limit: 1000MS   Memory Limit: 65536K       Description Bessie wants to navigate her s ...

  9. CentOS 7 & Chinese Fonts bug

    CentOS 7 & Chinese Fonts bug # check $ yum grouplist $ yum grouplist hidden # root $ yum groupin ...

  10. MySQL Workbench基本操作

    MySQL Workbench是一款专为MySQL设计的ER/数据库建模工具.它是著名的数据库设计工具DBDesigner4的继任者.你可以用MySQL Workbench设计和创建新的数据库图示,建 ...