World is Exploding
题意:
给出一个长为n的序列A,问有多少四元组(a, b, c, d)满足$a \ne b \ne c \ne d, 1 \leq a < b \leq n, 1 \leq c < d \leq n, A_a < A_b, A_c > A_d$.
解法:
容斥,考虑用正序对乘以逆序对后,得到的方案中四种不合法情况:
1.$c < d = a < b$
2.$a < b = c < d$
3.$a = c < d$ 且 $a = c < d$
4.$a < b = d$ 且 $c < b = d$
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> #define N 50010
#define LL long long
#define lb(x) (x&(-x)) using namespace std; int n, tot;
int a0[N], a[N], pre[N], suc[N]; int ask(int sum[], int x)
{
int ans = ;
for(int i = x; i > ; i -= lb(i))
ans += sum[i];
return ans;
} void add(int sum[], int x, int v)
{
for(int i = x; i <= tot && i>;i += lb(i))
sum[i] += v;
} LL qsum(int sum[], int l, int r)
{
if(l > r) return ;
return ask(sum, r) - ask(sum, l - );
} int main()
{
while(~scanf("%d", &n))
{
for(int i = ; i <= n; i++)
{
scanf("%d", &a[i]);
a0[i] = a[i];
suc[i] = ;
pre[i] = ;
}
sort(a0 + , a0 + n + );
tot = ;
for(int i = ; i <= n; i++)
if(a0[i] != a0[i-]) a0[++tot] = a0[i];
for(int i = ; i <= n; i++)
{
a[i] = lower_bound(a0 + , a0 + tot + , a[i]) - a0;
add(suc, a[i], );
}
LL ans = , cnt1 = , cnt2 = ;
for(int i = ; i <= n; i++)
{
add(pre, a[i], );
add(suc, a[i], -);
LL pre_higher = qsum(pre, a[i] + , tot);
LL pre_lower = qsum(pre, , a[i] - );
LL suc_higher = qsum(suc, a[i] + , tot);
LL suc_lower = qsum(suc, , a[i] - );
cnt1 += suc_higher;
cnt2 += suc_lower;
ans -= pre_higher * suc_higher;
ans -= pre_lower * suc_lower;
ans -= suc_lower * suc_higher;
ans -= pre_lower * pre_higher;
}
ans += cnt1 * cnt2;
cout << ans << endl;
}
return ;
}
World is Exploding的更多相关文章
- HDU 5792---2016暑假多校联合---World is Exploding
2016暑假多校联合---World is Exploding Problem Description Given a sequence A with length n,count how many ...
- 2016 Multi-University Training Contest 5 World is Exploding
转载自:http://blog.csdn.net/queuelovestack/article/details/52096337 [题意]给你一个序列A,选出四个下标不同的元素,下标记为a,b,c,d ...
- HDU 5792 World is Exploding 树状数组+枚举
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5792 World is Exploding Time Limit: 2000/1000 MS (Ja ...
- 2016 Multi-University Training Contest 5 1012 World is Exploding 树状数组+离线化
http://acm.hdu.edu.cn/showproblem.php?pid=5792 1012 World is Exploding 题意:选四个数,满足a<b and A[a]< ...
- HDU 5792 World is Exploding (树状数组)
World is Exploding 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5792 Description Given a sequence ...
- hdu_5792_World is Exploding(树状数组+逆序对)
题目链接:hdu_5792_World is Exploding 题意: 给你一个数列,让你找有多少个(a,b,c,d)满足a≠b≠c≠d,1≤a<b≤n,1≤c<d≤n,Aa<Ab ...
- hdu 5792 World is Exploding 树状数组
World is Exploding 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5792 Description Given a sequence ...
- 梯度消失(vanishing gradient)与梯度爆炸(exploding gradient)问题
(1)梯度不稳定问题: 什么是梯度不稳定问题:深度神经网络中的梯度不稳定性,前面层中的梯度或会消失,或会爆炸. 原因:前面层上的梯度是来自于后面层上梯度的乘乘积.当存在过多的层次时,就出现了内在本质上 ...
- This instability is a fundamental problem for gradient-based learning in deep neural networks. vanishing exploding gradient problem
The unstable gradient problem: The fundamental problem here isn't so much the vanishing gradient pro ...
- hdu-5792 World is Exploding(容斥+树状数组)
题目链接: World is Exploding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
随机推荐
- 7.JAVA编程思想笔记隐藏实施过程
欢迎转载,转载请标明出处:http://blog.csdn.net/notbaron/article/details/51040237 "进行面向对象的设计时,一项主要的考虑是:怎样将发生变 ...
- Java泛型 类型变量的限定
有时候,类和方法须要对类型变量加以约束.比方你有一个方法,你仅仅希望它接收某个特定类型及其子类型作为參数. 以下就举一个方法限定接收參数的类型的样例来说明怎样限定类型变量. 首先有几个简单的辅助类: ...
- anaconda的所有版本大全--下载地址
地址: https://repo.continuum.io/archive/ 内容: Anaconda installer archive Filename Size Last Modified MD ...
- PythonCookBook笔记——迭代器与生成器
迭代器与生成器 迭代是Python最强大的功能之一,虽然看起来迭代只是处理序列中元素的一种方法,但不仅仅如此. 手动遍历迭代器 想遍历但不想使用for循环. 使用next()方法并在代码中捕获Stop ...
- IO复用之select实现
前言 在看过前文:初探IO复用后,想必你已对IO复用这个概念有了初步但清晰的认识.接下来,我要在一个具体的并发客户端中实现它( 基于select函数 ),使得一旦服务器中的客户进程被终止的时候,客户端 ...
- 三星note3 N900刷机包 4.4.2 ZSUDNE3 官方原汁原味 稳定流畅
ROM介绍 此ROM基于最新的4.4.2 ZSUDNE3 制作,加入一些必要功能,其它性能基本与官方无差距,各方面感觉都非常不错了.此ROM本人自用,所以制作风格有点个人倾向.不论什么建议或者问题欢迎 ...
- 继承的文本框控件怎么响应EN_CHANGE等消息
继承的文本框控件如何响应EN_CHANGE等消息?我从CEdit继承了一个CMyEdit类,想在这个类里填写它的一些消息.我在消息映射表里写的是MESSAGE_HANDLER(EN_CHANGE, O ...
- 同一世界服务器架构--Erlang游戏服务器
Erlang最大的优点是方便,很多基础功能都已经集成到Erlang语言中.之前用C++写服务器的时候,管理TCP连接很繁琐,需要写一大堆代码来实现.底层的框架需要写很多代码实现,这样既浪费时间 ...
- spring 拦截器简介
spring 拦截器简介 常见应用场景 1.日志记录:记录请求信息的日志,以便进行信息监控.信息统计.计算PV(Page View)等.2.权限检查:如登录检测,进入处理器检测检测是否登录,如果没有直 ...
- c# winform 根据窗体自动调整控件
一.概述 本文要实现的功能是:当窗体最大化时,控件的大小可以随窗体一起变化.开发环境,vs2010 c# winform,窗体名称采用默认的Form1. 2.把调整控件大小的方法放到一个类中:Form ...