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 ...
随机推荐
- socket连接和TCP连接的关系
我们在数据传输时,能够仅仅使用(传输层)TCP/IP协议,可是那样的话,假设没有应用层.便无法识别数据内容,假设想要使传输的数据有意义.则必须使用到应用层协议,应用层协议有非常多,比方HTTP.FTP ...
- EMC机理------串扰
转:电子工程师不得不知道的EMC机理------串扰(韬略科技EMC) 串扰是信号完整性中最基本的现象之一,在板上走线密度很高时串扰的影响尤其严重.我们知道,线性无缘系统满足叠加定理,如果受害线上有信 ...
- [Java] 实验4參考代码
题目.提示.代码.解释都已公布. 提供这些的目的不是要求大家要写得像我写得这样,而是希望大家在实验后看看别人写的代码: 1. 提升理解代码的能力. 2. 不要自满于完毕题目.要明确你的 ...
- cmake学习之- cmake_parse_arguments
最后更新: 2019-06-08 一.指令介绍 cmake_parse_arguments 为解析函数(function)或 宏(macros) 参数的命令: cmake_parse_argument ...
- 【PHP开发】远程文件(图片)下载
这一篇文章介绍的方法不算原创了,只是引用的别人的文章,加上自己的注释,因为接触php时间不长,所以尝试的东西比较多,自己加的注释也比较简单,php高手请略过. 我要用到远程下载图片,是在做微信公众平台 ...
- C#高级编程 第十五章 反射
(二)自定义特性 使自定义特性非常强大的因素时使用反射,代码可以读取这些元数据,使用它们在运行期间作出决策. 1.编写自定义特性 定义一个FieldName特性: [AttributeUsage(At ...
- c# 备份数据
#region 备份数据文件 /// <summary> /// 备份数据文件 /// </summary> /// <param name="strFileN ...
- IOS获取当前地理位置文本
本文转载至 http://blog.csdn.net/lvxiangan/article/details/28101119 以下内容摘抄自网络,著作权属于原作者 方法1:使用ios自带联网查询功 ...
- jquery在网页实时显示时间;
1.定义一个显示时间的位置 <div id="shijian"> </div> 2.jquery代码 function showTime() { var c ...
- Java 集成域登陆
参考: 1. JAVA中使用jcifs集成AD域用户认证 2. https://liaosy.iteye.com/blog/1887092 3.其他库 https://github.com/Waffl ...