题意:

给出一个长为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的更多相关文章

  1. HDU 5792---2016暑假多校联合---World is Exploding

    2016暑假多校联合---World is Exploding Problem Description Given a sequence A with length n,count how many ...

  2. 2016 Multi-University Training Contest 5 World is Exploding

    转载自:http://blog.csdn.net/queuelovestack/article/details/52096337 [题意]给你一个序列A,选出四个下标不同的元素,下标记为a,b,c,d ...

  3. HDU 5792 World is Exploding 树状数组+枚举

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5792 World is Exploding Time Limit: 2000/1000 MS (Ja ...

  4. 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]< ...

  5. HDU 5792 World is Exploding (树状数组)

    World is Exploding 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5792 Description Given a sequence ...

  6. 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 ...

  7. hdu 5792 World is Exploding 树状数组

    World is Exploding 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5792 Description Given a sequence ...

  8. 梯度消失(vanishing gradient)与梯度爆炸(exploding gradient)问题

    (1)梯度不稳定问题: 什么是梯度不稳定问题:深度神经网络中的梯度不稳定性,前面层中的梯度或会消失,或会爆炸. 原因:前面层上的梯度是来自于后面层上梯度的乘乘积.当存在过多的层次时,就出现了内在本质上 ...

  9. 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 ...

  10. hdu-5792 World is Exploding(容斥+树状数组)

    题目链接: World is Exploding Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Jav ...

随机推荐

  1. rf-demos (request)

    *** Settings *** Library RequestsLibrary Library Collections Library XML *** Test Cases *** case1 Cr ...

  2. 无线热点登陆认证原理探究---captive portal

    什么是Captive Portal 大家肯定都连过公共场所的wifi热点,比如麦当劳等地方的.他们的wifi往往一连上去就会弹出一个要求登录或者微信关注之类的页面,只有在这个页面完成操作了才能正常访问 ...

  3. nightwatch.js - scroll until element is visible

    .getLocationInView() Determine an element's location on the screen once it has been scrolled into vi ...

  4. mysql连接超时的问题

    使用Hibernate + MySQL数据库开发,链接超时问题: com.mysql.jdbc.CommunicationsException: The last packet successfull ...

  5. UML类图关系表示方法

    本文转载: http://blog.csdn.net/fengsh998/article/details/8105631 分类: UML2012-10-24 10:18 1175人阅读 评论(0) 收 ...

  6. php 批量删除数据

    php 批量删除数据 :比如我们在看邮箱文件的时候,积攒了一段时间以后,看到有些文件没有用了 这时候我们就会想到把这些 没用的文件删除,这时候就用到了批量删除数据的功能,这里我是用了数据库原有的一个表 ...

  7. 在c代码中获取用户环境变量

    1 extern char ** environ 这是一个字符串数组,最后一个元素是null,即\0. 2 在代码中的使用方法 直接extern char **environ,然后 直接environ ...

  8. thinkphp权限管理Rbac实例

    首先,先建立Rbac那五张表(用户表,角色表,节点表,权限表,角色-用户表),后面四张可以在thinkphp中Rbac类里直接复制. 第二步,根据需求往那五张表里插入数据,注意:节点表里的节点名称一定 ...

  9. Spring AOP-xml配置

    在spring AOP(一)中介绍了AOP的基本概念和几个术语,现在学习一下在XML中如何配置AOP. 在XML中AOP的配置元素有以下几种: AOP配置元素 描述 <aop:config> ...

  10. bzoj4670: 佛罗里达

    这题直接随机化+贪心就可以爆踩过去,我加了个退火增加容错率而已....其实你随机的次数够多根本不需要... 然后来自肉丝哥哥的正经做法: 先钦定D(A)>D(B),那么可以枚举D(A),然后再去 ...