题意:

给出一个长为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. MySQL优化之——日志

    转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46790451 MYSQL里的日志主要分为4类,使用这些日志文件.能够查看MYSQL ...

  2. cvpr2017年的所有论文下载

    wget -c -N  --no-clobber --convert-links --random-wait -r -p -E -e robots=off -U mozilla   http://op ...

  3. jQuery AjaxUpload中文使用API和demo示例

    1.AjaxUpload上传插件 浏览器迫使我们使用文件输入控件(<input type=”file” />)做上传,然而此控件的样式是不能修改的.此外,基于表单上传在流行的Ajax应用程 ...

  4. fabric-ca安装

    1.Go版本1.7+(具体可参考Linux安装Go语言) 2.GOPATH环境变量正确配置 export GOROOT=/usr/local/go export GOPATH=/opt/gopath ...

  5. Android: 亲測解决模拟器启动慢的问题

    1.首先在相应的sdk manager里面下载一个4.03以上的api. 这里我选择的是4.2.2 (api17) 2.选择里面的" Intel Hardware Accelerated E ...

  6. iOS8 Push Notifications

    本文转载至 http://blog.csdn.net/pjk1129/article/details/39551887   原贴地址:https://parse.com/tutorials/ios-p ...

  7. 采用ADM2582E/ADM2587E实现完全半/全双工的RS-485/RS-422接口隔离

    RS-485标准是一种常见的总线架构,其通用性及远距离传输能力使其广泛应用于各种通信接口电路.在多数情况下,由于应用环境的恶劣,需要对RS-485接口采用隔离方案以防止出现接地环路. 对RS-485接 ...

  8. 在Windows平台用visual studio编译的可执行文件部署时报:应用程序无法正常启动0xc000007b(跟DirectX9无关的原因)

    最近在做EasyDarwin开源流媒体服务器Windows版本编译与部署时发现一个问题,在开发机本机运行都很正常,但是部署到目标机器(未安装vs等开发环境)时,莫名其妙报出了"应用程序无法正 ...

  9. 清理yum 缓存

    两条命令 yum clean all 以及 rm -rf /var/cache/yum/* 如何有效的清理yum缓存 - CSDN博客 https://blog.csdn.net/nsrainbow/ ...

  10. Mongoose学习(1)

    1.Schema : 一种以文件形式存储的数据库模型骨架,不具备数据库的操作能力    Model : 由Schema发布生成的模型,具有抽象属性和行为的数据库操作对    Entity : 由Mod ...