【36.86%】【codeforces 558B】Amr and The Large Array
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
Examples
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
【题目链接】:http://codeforces.com/contest/558/problem/B
【题解】
找到出现次数最多的数字是哪些(可能有多个);
然后看看哪一个数字(出现次数最多的那些数字)在原序列中出现的最左的位置和最右的位置的差最小;
那个差的最小值就是答案了;
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x)
#define pri(x) printf("%d",x)
#define prl(x) printf("%I64d",x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int MAXN = 1e5+10;
const int MAX = 1e6+100;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
struct abc
{
int l,r;
};
int n;
map <int,int> dic;
int a[MAXN];
abc b[MAX];
int main()
{
// freopen("F:\\rush.txt","r",stdin);
int ma = 0;
rei(n);
rep1(i,1,n)
{
rei(a[i]);
dic[a[i]]++;
if (dic[a[i]]>ma)
ma = dic[a[i]];
}
rep1(i,1,n)
{
if (dic[a[i]]==ma)
{
if (b[a[i]].l==0)
{
b[a[i]].l=i;
b[a[i]].r=i;
}
else
b[a[i]].r = i;
}
}
int qujian = 21e8;
int al,ar;
rep1(i,1,1e6)
if (b[i].l!=0)
{
int len = b[i].r-b[i].l+1;
if (len<qujian)
{
al = b[i].l,ar = b[i].r;
qujian = len;
}
}
pri(al);putchar(' ');pri(ar);
return 0;
}
【36.86%】【codeforces 558B】Amr and The Large Array的更多相关文章
- 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 ...
- 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...
- codeforces 558B. Amr and The Large Array 解题报告
题目链接:http://codeforces.com/problemset/problem/558/B 题目意思:给出一个序列,然后找出出现次数最多,但区间占用长度最短的区间左右值. 由于是边读入边比 ...
- 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
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller. ...
- 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 ...
- 【42.86%】【Codeforces Round #380D】Sea Battle
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【30.36%】【codeforces 740D】Alyona and a tree
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- [Angular] Create a custom validator for reactive forms in Angular
Also check: directive for form validation User input validation is a core part of creating proper HT ...
- Flume的Agent
Flume的Agent text(“filename”):将文件filename作为数据源,按行发送 tail(“filename”):探测filename新产生的数据,按行发送出去 fsyslogT ...
- Java学习笔记九
GUI:图形用户界面,Java不常用于创建桌面应用,所以用的比较少 一.概述: 二.Frame演示: 三.事件监听机制 import java.awt.Button; import java.awt. ...
- using可以用于释放操作,相当于Dispose()
using可以用于释放操作,相当于Dispose()
- ACM 中JAVA的应用
原文地址:http://www.cppblog.com/vontroy/archive/2010/05/24/116233.html 先说一下Java对于ACM的一些优点吧: (1) 对于熟悉C/C+ ...
- Linux系列-安装经常使用软件
安装JDK: 理论篇: 一.下载JDK 二.安装 ①复制到/usr/java/路径下 [plain] view plaincopy #mkdir /usr/java/ #cp jdk-7u25-lin ...
- Android平台中的三种翻页效果机器实现原理
本文给开发者集中展现了Android平台中的三种翻页效果机器实现原理,希望能够对开发者有实际的帮助价值! 第一种翻页效果如下: 实现原理: 当前手指触摸点为a,则 a点坐标为(ax,ay), ...
- Python产生随机数组,测试用
import numpy as np if __name__ == '__main__': a=np.random.randint(0,10,size=[3,3]) print(a) 输出: [ ...
- 【CS Round #46 (Div. 1.5) B】Letters Deque
[链接]h在这里写链接 [题意] 让你把一个正方形A竖直或水平翻转. 问你翻转一次能不能把A翻转成B [题解] 有说一定要恰好为1次. 并不是说A和B相同就一定不行. [错的次数] 2 [反思] 自己 ...
- amazeui页面分析之登录页面
amazeui页面分析之登录页面 一.总结 1.tpl命名空间:tpl命名空间的样式都是从app.css里面来的,app.css用用来移动网站开发的样式 2.表单样式:am-form到am-form- ...