Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C (用map 超时)
2 seconds
256 megabytes
standard input
standard output
Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.
For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.
There are non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.
The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — the number of balls.
The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ n) where ti is the color of the i-th ball.
Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color.
4
1 2 1 2
7 3 0 0
3
1 1 1
6 0 0
In the first sample, color 2 is dominant in three intervals:
- An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color.
- An interval [4, 4] contains one ball, with color 2 again.
- An interval [2, 4] contains two balls of color 2 and one ball of color 1.
There are 7 more intervals and color 1 is dominant in all of them.
题意: 给你n个数 共n*(n+1)/2个区间 求各个区间的众数作为标记数 若有多个众数 记录最小的数作为标记数 输出每个数 作为多少个区间的标记数
题解: 暴力处理 记录各个区间的标记数。
吃了 STL 的亏 用map 超时了 xjb用 用数组存就是 !!!!!
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<map>
#define ll __int64
#define pi acos(-1.0)
using namespace std;
int n;
int mp[5005];
int mpp[5005];
int a[5005];
int main()
{
//mp.clear();
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=1;i<=n;i++)
{
int maxc=-1;
int minx=5001;
int ans=0;
for(int j=1;j<=n;j++)
mpp[j]=0;
for(int j=i;j<=n;j++)
{
mpp[a[j]]++;
if(maxc==mpp[a[j]])
{
ans=min(ans,a[j]);
}
if(maxc<mpp[a[j]])
{
maxc=mpp[a[j]];
ans=a[j];
}
mp[ans]++;
}
}
cout<<mp[1];
for(int i=2;i<=n;i++)
printf(" %d",mp[i]);
cout<<endl;
return 0;
}
Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C (用map 超时)的更多相关文章
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B. Problems for Round 水题
B. Problems for Round 题目连接: http://www.codeforces.com/contest/673/problem/B Description There are n ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B
B. Problems for Round time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)只有A题和B题
连接在这里,->点击<- A. Bear and Game time limit per test 2 seconds memory limit per test 256 megabyte ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D Bear and Two Paths
题目链接: http://codeforces.com/contest/673/problem/D 题意: 给四个不同点a,b,c,d,求是否能构造出两条哈密顿通路,一条a到b,一条c到d. 题解: ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C - Bear and Colors
题目链接: http://codeforces.com/contest/673/problem/C 题解: 枚举所有的区间,维护一下每种颜色出现的次数,记录一下出现最多且最小的就可以了. 暴力n*n. ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths 构造
D. Bear and Two Paths 题目连接: http://www.codeforces.com/contest/673/problem/D Description Bearland has ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C. Bear and Colors 暴力
C. Bear and Colors 题目连接: http://www.codeforces.com/contest/673/problem/C Description Bear Limak has ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) A. Bear and Game 水题
A. Bear and Game 题目连接: http://www.codeforces.com/contest/673/problem/A Description Bear Limak likes ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)
A.暴力枚举,注意游戏最长为90分钟 B.暴力,c[l]++,c[r]--,记录中间有多长的段是大小为n的,注意特判m=0的情况 C.暴力枚举,我居然一开始没想出来!我一直以为每次都要统计最大的,就要 ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D
D. Bear and Two Paths time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
随机推荐
- python之打印九九乘法表
配置环境:python 3.6 python编辑器:pycharm 整理成代码如下: #!/usr/bin/env python #-*- coding: utf-8 -*- #九九乘法表 #分析:九 ...
- 齐博cms最新SQL注入网站漏洞 可远程执行代码提权
齐博cms整站系统,是目前建站系统用的较多的一款CMS系统,开源,免费,第三方扩展化,界面可视化的操作,使用简单,便于新手使用和第二次开发,受到许多站长们的喜欢.开发架构使用的是php语言以及mysq ...
- xss挑战赛小记 0x02(prompt(1))
0x0O 上次搜xss挑战赛的时候 还找到了一个看上去难度更高的挑战赛 今天做了一下 学到了很多新东西 这个挑战赛能够在页面成功prompt(1)就算过关了 挑战地址 http://prompt.ml ...
- XML文件中关键字自动提示和不全配置
一.获得mybatis-3-config.dtd.mybatis-3-mapper.dtd 这两个文件. 建立一个Maven的项目 在Pom.xml文件中的Mybatis jar包的下载设置(也可以从 ...
- vTaskDelete(NULL)使用注意事项
在实际开发过程中,记录犯过的一个错误,如下 vTaskDelete(NULL); iccid_return_num = ; 错误原因分析,在任务删除之后(调用vTaskDelete(NULL)之后), ...
- OrCAD把原理图中的器件添加到原理图库
1. 在使用OrCAD的时候,有时需要把别人的原理图里面的器件添加到自己的原理图库,方便以后使用,具体操作如下,依次选择Design Cache---元器件--Copy 2. 选中要存放的原理图库,鼠 ...
- java线程池技术
1.线程池的实现原理?简介: 多线程技术主要解决处理器单元内多个线程执行的问题,它可以显著减少处理器单元的闲置时间,增加处理器单元的吞吐能力.假设一个服务器完成一项任务所需时间为:T1 创建线程时间, ...
- BZOJ 1968 [Ahoi2005]COMMON 约数研究:数学【思维题】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1968 题意: 设f(x) = x约数的个数.如:12的约数有1,2,3,4,6,12,所以 ...
- 安装配置hadoop
在master中安装并且配置hadoop (1).将hadoop-2.6.4.tar.gz安装包复制到hadoop文件目录下(直接赋值进去就行) (2).解压安装包haoddp-2.6.4.tar.g ...
- 装机、UEFI双系统安装
装机设置 设置默认中图标显示查看-选项-查看-应用到文件夹 控制面板-语言-管理输入法 word-选项-取消输入法设置处于活动状态word-字体-设置默认值 高DPI的显示屏,需要使用125%的缩放, ...