codeforces 558B B. 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
题意:
使数组的魅力值保持相同,但数组的长度尽量小;
思路:
用vector的大小来看是否对应魅力值的那个数,而vector保存了这个数的各个位置,可以得到长度,一半比较一边更新就好;
AC代码:
/*
2014300227 558B - 9 GNU C++11 Accepted 61 ms 15728 KB
*/
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+;
typedef long long ll;
const double PI=acos(-1.0);
int n,a[N];
vector<int>ve[*N];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
ve[a[i]].push_back(i);
}
int ans=,l=,r=;
for(int i=;i<=1e6;i++)
{
int g=ve[i].size();
if(g){
if(g>ve[ans].size())
{
int len=g;
l=ve[i][];
r=ve[i][len-];
ans=i;
}
else if(g==ve[ans].size())
{
int s=g;
if(ve[i][s-]-ve[i][]<r-l)
{
l=ve[i][];
r=ve[i][s-];
ans=i;
}
}
}
}
cout<<l<<" "<<r<<endl; return ;
}
codeforces 558B B. Amr and The Large Array(水题)的更多相关文章
- 【36.86%】【codeforces 558B】Amr and The Large Array
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 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 ...
- 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 ...
- 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. ...
- CF451B Sort the Array 水题
Codeforces Round #258 (Div. 2) Sort the Array B. Sort the Array time limit per test 1 second memory ...
- codeforces 14A - Letter & codeforces 859B - Lazy Security Guard - [周赛水题]
就像title说的,是昨天(2017/9/17)周赛的两道水题…… 题目链接:http://codeforces.com/problemset/problem/14/A time limit per ...
- Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题
A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...
- Codeforces Round #115 B. Plane of Tanks: Pro 水题
B. Plane of Tanks: Pro Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/17 ...
随机推荐
- template.js文档
参见GitHub:https://github.com/yanhaijing/template.js/ template.js简介: template.js 一款javascript模板引擎,简单,好 ...
- 一种把dll放在不同目录的巧妙方法
想必C#的开发者都遇到过这个问题,引用的dll都放在根目录下,随着项目的日益增大,根目录下充满了各种各样的dll,非常的不美观. 如果能够把dll按照想要的目录来存放,那么系统就美观多了,以下是我常用 ...
- 30:根据排序标识flag给数组排序
题目描述:输入整型数组和排序标识,对其元素按照升序或降序进行排序 接口说明 原型: void sortIntegerArray(Integer[] pIntegerArray, int iSortFl ...
- nginx 代理模式下,获取客户端真实IP
最近做博友推荐,发现个小问题,用$_SERVER['REMOTE_ADDR'];得到的都是服务器的地址192.168.96.52,搜索了一下,发现问题,改为$_SERVER['HTTP_X_REAL_ ...
- Java的Executor框架和线程池实现原理
Java的Executor框架 1,Executor接口 public interface Executor { void execute(Runnable command); } Executor接 ...
- MySQL常见的数据类型(八)
不多说,直接上干货! MySQL常见的数据类型 一.数据类型是什么? 数据类型是指列.存储过程参数.表达式和局部变量的数据特征,它决定了数据的存储格式,代表了不同的信息类型. 有一些数据是要存储为数字 ...
- python 基础 9.2 mysql 事务
一. mysql 事务 MySQL 事务主要用于处理操作量大,复杂度高的数据.比如,你操作一个数据库,公司的一个员工离职了,你要在数据库中删除它的资料,也要删除该人员相关的,比如邮箱,个人资产等 ...
- rabbitmq 安装-单点
centos6.5 rabbitmq搭建 环境:centos6.5 192.168.9.41 安装rabbitmq需要先安装erlang.rabbitmq3.6版本需要erlang R16B03 ...
- npm install --save 、--save-dev 、-D、-S 的区别与NODE_ENV的配置
https://blog.csdn.net/jwl_willon/article/details/81054978 1.npm install <=> npm i --save < ...
- java中使用js函数
JDK6已经发布很久了,很早就听过他已经支持脚本语言了,不过一直没有时间尝试,今天偷闲试了一下,感觉不错. javax.script包它是Java新增的操作脚本的工具包, 利用它我们可以对脚本语言进行 ...