题目描述

Snuke loves constructing integer sequences.

There are N piles of stones, numbered 1 through N. The pile numbered i consists of ai stones.

Snuke will construct an integer sequence s of length Σai, as follows:

Among the piles with the largest number of stones remaining, let x be the index of the pile with the smallest index. Append x to the end of s.

Select a pile with one or more stones remaining, and remove a stone from that pile.

If there is a pile with one or more stones remaining, go back to step 1. Otherwise, terminate the process.

We are interested in the lexicographically smallest sequence that can be constructed. For each of the integers 1,2,3,…,N, how many times does it occur in the lexicographically smallest sequence?

Constraints

1≤N≤105

1≤ai≤109

输入

The input is given from Standard Input in the following format:

N

a1 a2 … aN

输出

Print N lines. The i-th line should contain the number of the occurrences of the integer i in the lexicographically smallest sequence that can be constructed.

样例输入

2

1 2

样例输出

2

1

分析:偷看题解,慢慢写出来的。。。。

#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#define range(i,a,b) for(int i=a;i<=b;++i)
#define LL long long
#define rerange(i,a,b) for(int i=a;i>=b;--i)
#define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
using namespace std;
int n;
LL ans[];
pair<LL,LL>aa[];
bool cmp(pair<LL,LL>a,pair<LL,LL>b){
return a.second>b.second;
}
void init() {
cin>>n;
fill(ans,);
range(i,,n){
aa[i].first=i;
cin>>aa[i].second;
}
sort(aa+,aa++n,cmp);
aa[n+].second=;
}
void solve(){
LL tmp=,num=aa[].first;
range(i,,n+){
if(aa[i].second==aa[i-].second)++tmp;
else ans[num]+=(aa[i-].second-aa[i].second)*(tmp++);
if(aa[i].first<num)num=aa[i].first;
}
range(i,,n)printf("%lld\n",ans[i]);
}
int main() {
init();
solve();
return ;
}

Frequency的更多相关文章

  1. [LeetCode] Sort Characters By Frequency 根据字符出现频率排序

    Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: ...

  2. [LeetCode] Word Frequency 单词频率

    Write a bash script to calculate the frequency of each word in a text file words.txt. For simplicity ...

  3. 451. Sort Characters By Frequency

    题目: Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Inp ...

  4. Sort Characters By Frequency

    Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: ...

  5. CPU frequency and voltage scaling code in the Linux(TM) kernel

    CPU frequency and voltage scaling code in the Linux(TM) kernel CPU frequency scaling Using CPUfreq G ...

  6. High Frequency Trading (整理中...)

    什么是高频交易系统 1 交易指令完全是由电脑发送,对市场数据的响应延时在微秒级2 系统有专用的软硬件组成,研发时需要大量的计算机专家级的工作3 系统的硬件需要放在离交易所主机很近的位置,所谓co-lo ...

  7. [CareerCup] 17.9 Word Frequency in a Book 书中单词频率

    17.9 Design a method to find the frequency of occurrences of any given word in a book. 这道题让我们找书中单词出现 ...

  8. Leetcode: Sort Characters By Frequency

    Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: ...

  9. LTE Module User Documentation(翻译13)——频率复用算法(Frequency Reuse Algorithms)

    LTE用户文档 (如有不当的地方,欢迎指正!)   19 Frequency Reuse Algorithms(频率复用算法)   本节我们将描述如何在 LTE 仿真中使用频率复用(FR)算法.共有两 ...

  10. Individual Project - Word frequency program-11061171-MaoYu

    BUAA Advanced Software Engineering Project:  Individual Project - Word frequency program Ryan Mao (毛 ...

随机推荐

  1. Ironic-Python-Agent

    Ironic-Python-Agent 在PXE部署环境中,deploy模块是通过打开一个iSCSI设备,ironic-conductro将OS的镜像文件写到iSCSI的设备,所以deploy_ram ...

  2. glance上传镜像

    glance image-create --name "centos68-test" --file centos68.dsk \ --disk-format raw --conta ...

  3. OpenStack-Ironic裸金属简介

    一,Ironic简述 简而言之,OpenStack Ironic就是一个进行裸机部署安装的项目.    所谓裸机,就是指没有配置操作系统的计算机.从裸机到应用还需要进行以下操作:  (1)硬盘RAID ...

  4. 【转】在Unity中读写文件数据:LitJSON快速教程

    作者:王选易,出处:http://www.cnblogs.com/neverdie/ 欢迎转载,也请保留这段声明.如果你喜欢这篇文章,请点[推荐].谢谢! 介绍 JSON是一个简单的,但功能强大的序列 ...

  5. Java进行身份证格式强校验(准)

    最近做了一个系统,涉及到对用户输入的身份证号进行校验,减少脏数据传入后台处理并降低企业验证成本,因此在接入层便对输入信息做格式强校验. 直接附上代码,可直接使用. package hope.ident ...

  6. C#类和类成员初始化顺序

    1.不带静态成员的普通类,首先通过构造函数初始化. 2.带静态属性的类,无论是普通类还是静态类,都会先初始化静态字段,再执行构造函数. 3.类初始化时,不会执行类中方法,无论是否是静态.若想执行方法, ...

  7. 手把手搭建一个完整的javaweb项目

    手把手搭建一个完整的javaweb项目 本案例使用Servlet+jsp制作,用MyEclipse和Mysql数据库进行搭建,详细介绍了搭建过程及知识点. 下载地址:http://download.c ...

  8. Maven项目消除奇怪的红叉

    当项目截然无误,然则Eclipse总是出现红叉的时候,右键点击项目->Maven->Update Project-,进而纠正之.很简答的操作. 木头大哥所发的文章均基于自身实践,各位江湖好 ...

  9. mysql慢查询工具

    GeorgeHao 安装过程: [root@localhost-centos6 ~]# wget percona.com/get/pt-query-digest [root@localhost-cen ...

  10. SQL Server 中使用 Try Catch 处理异常

    CREATE TABLE ErrorLog( errNum INT, ErrSev ), ErrState INT, ErrProc ), ErrLine INT, ErrMsg ) ) CREATE ...