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 ...
随机推荐
- PDOHelper (原创)
class PDOHelper{ public static $db =null;// new PDO('mysql:host=192.168.1.68;dbname=test','root','12 ...
- guice基本使用,配置模块的两种方式(三)
guice是使用module进行绑定的,它提供了两种方式进行操作. 第一种是继承AbstractModule抽象类. package com.ming.user.test; import com.go ...
- mvc中Html.AntiForgeryToken的作用和用法
参考:http://blog.csdn.net/cpytiger/article/details/8781457
- 关于各浏览器下Hack的写法
下面是我收集有关于各浏览器下Hack的写法: 1.Firefox @-moz-document url-prefix() { .selector { property: value; } } 上面是仅 ...
- salt-master迁移
1.在迁移到的目标机器上先安装salt-master 2.把原master机器上的/etc/salt/pki目录打包发送到迁移的机器上的同等目录下面 3.在原master机器上批量修改minion的配 ...
- java操作Excel的poi的简介
一.POI概述 Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能. 结构: HSSF - 提供读写Mi ...
- 采用requests库构建简单的网络爬虫
Date: 2019-06-09 Author: Sun 我们分析格言网 https://www.geyanw.com/, 通过requests网络库和bs4解析库进行爬取此网站内容. 项目操作步 ...
- ack 工具
ack-tools ack其实就是快速查找工具,但centos在没有这个安装包. 下载安装 cd /tmp git clone https://github.com/dongci/ack.git cd ...
- Javase 简单代码练习
public class Test10 { public static void main(String[] args) { System.out.println("------------ ...
- Nginx+keepalived双机热备(默认路径安装)- 基础篇
负载均衡技术对于一个网站尤其是大型网站的web服务器集群来说是至关重要的!做好负载均衡架构,可以实现故障转移和高可用环境,避免单点故障,保证网站健康持续运行.关于负载均衡介绍,可以参考:linux负载 ...