题目描述

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. 孤荷凌寒自学python那些事第一天

    孤荷凌寒自学python第一天 初识python (学习过程的完整录像分享链接在文末,手写笔记图片在文末) 一种编程语言,首先是它的语言的基本架构,python总体让人耳目一新: 今天其实只接触到了它 ...

  2. Oz代码梳理

    https://files.cnblogs.com/files/gushiren/oz%E6%B5%81%E7%A8%8B%E5%9B%BE.pdf https://files.cnblogs.com ...

  3. ironic baremetal node rescue/unrescue mode

    环境ironic-api ironic-conductor,ironicclient均升级为Queens版本 官网说明API版本为1.38才支持rescue/unrescue,所以修改下openrc文 ...

  4. android 远程Service以及AIDL的跨进程通信

    在Android中,Service是运行在主线程中的,如果在Service中处理一些耗时的操作,就会导致程序出现ANR. 但如果将本地的Service转换成一个远程的Service,就不会出现这样的问 ...

  5. PHP7 深入理解

    读 PHP7的内核剖析 php7-internal 记录 3 PHP的相关组成 3.1 SAPI php常见的四种运行模式 SAPI:Server Application Programming In ...

  6. MyBatis:SQL语句中的foreach标签的详细介绍

    foreach 也就是遍历迭代,在SQL中通常用在 in 这个关键词的后面 foreach元素的属性主要有 item,index,collection,open,separator,close. 分别 ...

  7. killer驱动

    因为老的killer驱动会导致内存泄漏,killer官网网速又有如翔一般,在这里发个安装包 https://pan.baidu.com/s/1YtUrrOR74ShyDDNjHUAXBw

  8. 模拟Json格式传值请求与数据接收

    a.php代码: function http_post_json($url, $jsonStr) { $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, ...

  9. NGINX: 优化 use 参数

    转自:http://blog.sina.com.cn/s/blog_5eaf88f10100gkrq.html Nginx use参数分析对比 下图对比了poll select epoll和kqueu ...

  10. 翻煎饼_简单模拟_C++

    一.题目描述(懒人可直接跳过看题目概述) 题目来源: SWUST OJ  题目0254 http://acm.swust.edu.cn/problem/0254/ 二.问题概述 给出一列数,每次可将包 ...