题目描述

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. Cannot create a secure XMLInputFactory --CXF调用出错

    在调用方法前加上下面三句即可调用成功: Properties props = System.getProperties(); props.setProperty("org.apache.cx ...

  2. OpenFlow-Enaling innvation in Campus Networks

    OpenFlow-Enaling innvation in Campus Networks 出现问题 背景 Networks have become part of the critical infr ...

  3. css控制文字模糊

    *{ color: transparent; text-shadow: #111 0 0 5px; }

  4. hexo站点地图

    将网站链接提交到百度 百度搜索引擎提交入口 有三种验证方式,我选择Html标签验证,在themes\next\layout\_partials\head.swing中添加验证代码: <meta ...

  5. NSOperation 开发

    目录 1.简介 2.Operation对象 3.自定义Operation对象 4.通过Operation Queues运行Operation对象 5.手动运行Operation对象 一.简介 Coco ...

  6. 安装JDK以及配置Java运行环境

    安装JDK以及配置Java运行环境 1.JDK下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2 ...

  7. android的apk文件结构

    什么是APK?APK文件都由那些组成?不懂没关系,让小编来为你详细解答. 一.APK简介与描述 APK是AndroidPackage的缩写,即Android安装包(apk).APK是类似Symbian ...

  8. TCP面试题之四次挥手过程

    TCP四次挥手过程: 1.第一次挥手:Client发送一个FIN,用来关闭Client到Server的数据传送,Client进入FIN_WAIT_1状态: 2.第二次挥手:Server收到FIN后,发 ...

  9. 棘手的操作(bzoj 2333)

    Description 有N个节点,标号从1到N,这N个节点一开始相互不连通.第i个节点的初始权值为a[i],接下来有如下一些操作: U x y: 加一条边,连接第x个节点和第y个节点 A1 x v: ...

  10. Java并发容器--ConcurrentLinkedQueue

    概述 ConcurrentLinkedQueue是一种基于链表实现的无界非阻塞线程安全队列,遵循先入先出规则. 线程安全队列有两种实现方式: 阻塞方式:对入队和出队操作加锁.阻塞队列. 非阻塞方式:通 ...