题意:

给出一个长为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. man screen

    http://www.gnu.org/software/screen/manual/screen.html Screen User's Manual Next: Overview, Previous: ...

  2. 前端UI框架整理

    JQuery Jquery官网:http://jquery.com/ jQuery是一个快速,小巧,且功能丰富的JavaScript库. Jquery-1.11.3.min.js 压缩版:http:/ ...

  3. HTML5开发移动web应用—JQuery Mobile(1)

    JQuery Mobile是一个简单易用的web移动app开发框架.使用它就像使用jQuery一样,引入必要的文件就可以. 最基础的jQuery Mobile文件的结构代码例如以下: <body ...

  4. Python list 和 str 互转

    一.list转字符串 命令:''.join(list)其中,引号中是字符之间的分割符,如“,”,“;”,“\t”等等如:list = [1, 2, 3, 4, 5]''.join(list) 结果即为 ...

  5. Android与WebView的插件管理机制

    上一篇文章说到,当利用WebViewClient或者WebChromeClient来处理由html页面传过来的请求的时候,都会将相应的服务名称,操作方法和相应的參数数据传给一个叫PluginManag ...

  6. 从架构层面杜绝lua中使用未定义的变量

    # 从架构层面杜绝lua中使用未定义的变量 标签(空格分隔): lua --- lua中有一个很坑的地方:1.就是如果一个变量拼写错误,会自动的认为你定义了一个值为nil的全局变量.2.如果在func ...

  7. spring+mybatis多数据源,动态切换

    有时我们项目中需要配置多个数据源,不同的业务使用的数据库不同 实现思路:配置多个dataSource ,再配置多个sqlSessionFactory,和dataSource一一对应.重写SqlSess ...

  8. 剑指Offer:重建二叉树【7】

    剑指Offer:重建二叉树[7] 题目描述 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1,2,4,7,3,5 ...

  9. CSS3学习笔记(4)—上下滑动展开的按钮

    最近写了一个动画,下面来看看我以前写的一个上下滑动展开的按钮效果: 这类的效果经常会在一些网站页面下载按钮处看到,当你鼠标悬浮在下载按钮时,会提醒你是否已注册,或者点击登录什么的小提示~~~~~ 一. ...

  10. hihocoder #1062 : 最近公共祖先·一(小数据量 map+set模拟+标记检查 *【模板】思路 )

    #1062 : 最近公共祖先·一 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho最近发现了一个神奇的网站!虽然还不够像58同城那样神奇,但这个网站仍然让小Ho乐在 ...