Codeforces 558B Amr and The Large Array
1 second
256 megabytes
standard input
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.
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 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.
5
1 1 2 2 1
1 5
5
1 2 2 3 1
2 3
6
1 2 2 1 1 2
1 5
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 <iostream>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
using namespace std; const double PI = acos(-1.0);
const double e = 2.718281828459;
const double eps = 1e-8; struct node
{
int num;
int time;
int l;
int r;
int range;
} index[1000010]; int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int n;
while(cin>>n)
{
map<int, int>g;
g.clear();
memset(index, 0, sizeof(index));
int t;
int d = 0;
int dd;
int maxd = 1;
int maxtime = 0;
int maxrange = 1;
for(int i = 1; i <= n; i++)
{
scanf("%d", &t);
if(g[t] != 0)
{
dd = g[t];
index[dd].time++;
index[dd].r = i;
index[dd].range = index[dd].r-index[dd].l+1;
if(maxtime<index[dd].time || maxtime==index[dd].time&&maxrange>index[dd].range)
{
maxtime = index[dd].time;
maxd = dd;
maxrange = index[dd].range;
}
}
else
{
g[t] = ++d;
dd = g[t];
index[dd].num = t;
index[dd].time = 1;
index[dd].l = index[dd].r = i;
index[dd].range = 1;
if(maxtime < index[dd].time)
{
maxtime = index[dd].time;
maxd = dd;
maxrange = 1;
}
}
}
printf("%d %d\n", index[maxd].l, index[maxd].r);
}
return 0;
}
Codeforces 558B Amr and The Large Array的更多相关文章
- codeforces 558B. Amr and The Large Array 解题报告
题目链接:http://codeforces.com/problemset/problem/558/B 题目意思:给出一个序列,然后找出出现次数最多,但区间占用长度最短的区间左右值. 由于是边读入边比 ...
- codeforces 558B Amr and The Large Array-yy
题意:有一个数组.如今要削减它的尺寸.数组中同样元素的个数的最大值为数组的魅力值,要求削减后魅力值不能降低,同一时候要尽可能的把尺寸减到最小 分析:水题,主要是不要想复杂了.还有就是沉下心来做 代码: ...
- 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 ...
- 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 ...
- 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 ...
- CF 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 ...
- 【36.86%】【codeforces 558B】Amr and The Large Array
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 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. ...
- CodeForces 558B
Description Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make ...
随机推荐
- php 判断字符串包含中文(转)
$str = "测试中文"; echo $str; echo "<hr>"; //if (preg_match("/^[".ch ...
- MongoDB Master-Slave cluster with authentication setup
Master Server create mongo db folder with sub folders like data, conf, && log mkdir -p /opt/ ...
- 字符串比较——compareTo函数
package com.day03.ifelse; import java.math.BigInteger; /** * @author 王恒 * @datetime 2017年4月7日 下午3:13 ...
- Solr.NET快速入门(四)【相似查询,拼写检查】
相似查询 此功能会返回原始查询结果中返回的每个文档的类似文档列表. 参数通过QueryOptions的MoreLikeThis属性定义. 示例:搜索"apache",为结果中的每个 ...
- 使用C#正则表达式获取必应每日图片地址
微软的Bing搜索引擎首页每天都会提供了一些有趣的图片,下面使用正则表达式获取图片的地址,不管是在手机app还是在网站上都是很好的图片素材,而且每天更新,非常不错. 首先访问微软的API,该地址返回的 ...
- JDK和Cglib实现动态代理实例及优缺点分析
Spring AOP使用的核心技术是动态代理,说到动态代理就不得不和设计模式中的代理模式联系起来,通过代理模式我们可以对目标类进行功能增强,在某个方法的执行前后增加一些操作,例如计算方法执行效率.打印 ...
- Ubuntu安装配置Python.pyDev
一:安装ECLipse Eclipse官网下载软件tar包: 使用解压命令: sudo tar xzvf xxxxx.tar.gz -c /opt/ 创建快捷方式到桌面. 二:安装python-Num ...
- Eclipse中添加对Python的中文支持
原文链接:http://down.51cto.com/data/751371 首先要确保eclipse编辑器环境的编码为utf8,这个是大前提:其次如果py文件中含有中文字符的话,需要在py文件中对编 ...
- jdbc转账操作
public class cs{ public static void main(String[] args){ try{ Connection conn=JdbcUtils.getConnectio ...
- 图片放大不失真软件PhotoZoom如何使用?
PhotoZoom可以将我们一些过于像素低的照片可以无失真放大,那么PhotoZoom是如何实现无失真照片放大的呢? 以上图像中的编号表示每个步骤应操作的位置. 单击“打开”,并选择您想调整大小的图像 ...