D. Imbalanced Array
(单调栈)
void work()
{
top=,S[]=P(N,);
F(i,,n)
{
while(S[top].first<=a[i])top--;
l[i]=S[top].second+;
S[++top]=P(a[i],i);
}
top=,S[]=P(N,n+);
for(int i=n;i;i--)
{
while(S[top].first<a[i])top--;
r[i]=S[top].second-;
S[++top]=P(a[i],i);
}
F(i,,n)ans+=1ll*a[i]*(i-l[i]+)*(r[i]-i+);
} int main(){
scanf("%d",&n);
F(i,,n)scanf("%d",a+i);
work();
F(i,,n)a[i]*=-;
work();
printf("%lld\n",ans);
return ;
}
D. Imbalanced Array的更多相关文章
- Educational Codeforces Round 23 D. Imbalanced Array 单调栈
D. Imbalanced Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- [单调栈]Imbalanced Array
I m b a l a n c e d A r r a y Imbalanced Array ImbalancedArray 题目描述 You are given an array a a a con ...
- Imbalanced Array CodeForces - 817D (思维+单调栈)
You are given an array a consisting of n elements. The imbalance value of some subsegment of this ar ...
- 817D. Imbalanced Array 预处理最大最小 思维
LINK 题意:给出n个数,求所有子区间的最大最小值差的和. 思路:过去有道题目是求所有子区间的最大值或最小值,这题类似,我们对每一个数计算其作为最大值得次数和最小值的次数,这两个值求法类似,都是比左 ...
- codeforces 817 D. Imbalanced Array(单调栈+思维)
题目链接:http://codeforces.com/contest/817/problem/D 题意:给你n个数a[1..n]定义连续子段imbalance值为最大值和最小值的差,要你求这个数组的i ...
- Educational Codeforces Round 23 A-F 补题
A Treasure Hunt 注意负数和0的特殊处理.. 水题.. 然而又被Hack了 吗的智障 #include<bits/stdc++.h> using namespace std; ...
- 论文解读(GraphSMOTE)《GraphSMOTE: Imbalanced Node Classification on Graphs with Graph Neural Networks》
论文信息 论文标题:GraphSMOTE: Imbalanced Node Classification on Graphs with Graph Neural Networks论文作者:Tianxi ...
- javascript中的Array对象 —— 数组的合并、转换、迭代、排序、堆栈
Array 是javascript中经常用到的数据类型.javascript 的数组其他语言中数组的最大的区别是其每个数组项都可以保存任何类型的数据.本文主要讨论javascript中数组的声明.转换 ...
- ES5对Array增强的9个API
为了更方便的对Array进行操作,ES5规范在Array的原型上新增了9个方法,分别是forEach.filter.map.reduce.reduceRight.some.every.indexOf ...
随机推荐
- 前端学习 之 Bootstrap (一)
中文文档 一.前言 1.简介 Bootsrtap作为一个前端框架,开箱即用,封装了前段开发的大量底层细节,开放灵活,对响应式设计网页很好支持,组件丰富,社区活跃. 特点: 可重用性 一致性 灵活的栅栏 ...
- SP8093 JZPGYZ - Sevenk Love Oimaster(广义后缀自动机)
题意 题目链接 Sol 广义后缀自动机板子题..和BZOJ串那个题很像 首先建出询问串的SAM,然后统计一下每个节点被多少个串包含 最后直接拿询问串上去跑就行了 #include<bits/st ...
- gson解析json
json介绍 JSON(JavaScript Object Notation, JS 对象标记) 是一种轻量级的数据交换格式.它基于 ECMAScript 规范的一个子集,采用完全独立于编程语言的文本 ...
- python中if else流程判断
_username='Lily' _password=' username=input("username:") password=input("password:&qu ...
- bs4爬虫入门
# -*- coding: utf-8 -*- """ Created on Fri Nov 16 13:35:33 2018 @author: zhen "& ...
- centos7安装rabbitmq 总结
centos7下安装rabbitmq 折腾了三天最后做了以下总结 先查看一电脑名 :示例 #hostname name 查看一下hosts配置文件:如果如下结果,就要修改下 #cat /etc/ho ...
- Postgre SQL连接服务器失败
首先这是登陆postgre sql时提示的错误信息: psql: 无法联接到服务器: Connection refused (0x0000274D/10061) 服务器是否在主机 &qu ...
- 修改Devexpress DateEdit控件默认的日期格式和日历风格
最近项目中很多地方使用到DevExpress的DateEdit控件,而且设置都是一致(日期格式.选择日期的日历的风格等).每一次都需要设置太痛苦,因此需要寻找一种高效的解决方式. 一. 设置好一个作为 ...
- 【PAT】B1043 输出PATest(20 分)
/* */ #include<stdio.h> #include<algorithm> #include<string.h> #include<ctype.h ...
- Kali Linux 初始化配置:Apache2 /SSH /FTP
Kali Linux是基于Debian的Linux发行版, 设计用于数字取证操作系统.Kali Linux预装了许多渗透测试软件,包括nmap .Wireshark .John the Ripper, ...