Frequency
题目描述
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的更多相关文章
- [LeetCode] Sort Characters By Frequency 根据字符出现频率排序
Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: ...
- [LeetCode] Word Frequency 单词频率
Write a bash script to calculate the frequency of each word in a text file words.txt. For simplicity ...
- 451. Sort Characters By Frequency
题目: Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Inp ...
- Sort Characters By Frequency
Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: ...
- 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 ...
- High Frequency Trading (整理中...)
什么是高频交易系统 1 交易指令完全是由电脑发送,对市场数据的响应延时在微秒级2 系统有专用的软硬件组成,研发时需要大量的计算机专家级的工作3 系统的硬件需要放在离交易所主机很近的位置,所谓co-lo ...
- [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. 这道题让我们找书中单词出现 ...
- Leetcode: Sort Characters By Frequency
Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: ...
- LTE Module User Documentation(翻译13)——频率复用算法(Frequency Reuse Algorithms)
LTE用户文档 (如有不当的地方,欢迎指正!) 19 Frequency Reuse Algorithms(频率复用算法) 本节我们将描述如何在 LTE 仿真中使用频率复用(FR)算法.共有两 ...
- Individual Project - Word frequency program-11061171-MaoYu
BUAA Advanced Software Engineering Project: Individual Project - Word frequency program Ryan Mao (毛 ...
随机推荐
- Jmeter beanshell preprocessor随机添加任意多个请求参数
介绍下本次使用beanshell preprocessor的原因: 1.系统下可添加产品,一个产品可以有多个产品主题(比如:产品A(杭州三日游)拥有三个主题(研学.红学.夏令营)),我们在每次添加产品 ...
- 1064 Complete Binary Search Tree (30 分)(二叉查找树)
中序遍历建树 #include<bits/stdc++.h> using namespace std; ; int s[N]; int n; int tree[N]; int cnt; v ...
- 动态删边SPFA: [HNOI2014]道路堵塞
[HNOI2014]道路堵塞 题目描述 $A$ 国有 $N$座城市,依次标为$1$到$N$.同时,在这$N$座城市间有$M$条单向道路,每条道路的长度是一个正整数.现在,$A$国交通部指定了一条从城市 ...
- Python读写tap设备
#!/usr/bin/python import os import struct import fcntl import binascii TUNSETIFF = 0x400454ca IFF_TA ...
- jQuery选择器之id选择器
页面的任何操作都需要节点的支撑,开发者如果快速高效的找到指定的节点也是前端开发中的一个重点.jQuery提供了一系列的选择器帮助开发者达到这一目的,让开发者可以更少的处理复杂选择过程与性能优化,更多专 ...
- 如何从List中删除元素
从List中删除元素,不能通过索引的方式遍历后删除,只能使用迭代器. 错误的实现 错误的实现方法 public class Demo { public static void main(Str ...
- 在Android和iOS中集成flutter
flutter可能是未来跨平台开发的又一技术框架,那么对于一个app,我们不可能完全用flutter来开发,那么就意味着我们需要在已有的Android和iOS代码中去集成flutter.目前这一技术还 ...
- Spring Boot RabbitMQ 延迟消息实现完整版
概述 曾经去网易面试的时候,面试官问了我一个问题,说 下完订单后,如果用户未支付,需要取消订单,可以怎么做 我当时的回答是,用定时任务扫描DB表即可.面试官不是很满意,提出: 用定时任务无法做到准实时 ...
- bzoj 2618 半平面交模板+学习笔记
题目大意 给你n个凸多边形,求多边形的交的面积 分析 题意\(=\)给你一堆边,让你求半平面交的面积 做法 半平面交模板 1.定义半平面为向量的左侧 2.将所有向量的起点放到一个中心,以中心参照进行逆 ...
- ci的数据库地址
CI在linux服务器上运行的时候,数据库配置主机名的时候必须是127.0.0.1,而不是localhost.并且phpmyadmin也有这样的要求