Given a sequence A with length n,count how many quadruple (a,b,c,d) satisfies: a≠b≠c≠d,1≤a<b≤n,1≤c<d≤n,Aa<Ab,Ac>Ada≠b≠c≠d,1≤a<b≤n,1≤c<d≤n,Aa<Ab,Ac>Ad.

InputThe input consists of multiple test cases. 
Each test case begin with an integer n in a single line.

The next line contains n integers A1,A2⋯AnA1,A2⋯An. 
1≤n≤500001≤n≤50000 
0≤Ai≤1e90≤Ai≤1e9OutputFor each test case,output a line contains an integer.Sample Input

4
2 4 1 3
4
1 2 3 4

Sample Output

1
0 因为只考虑相对大小关系,所以先将数据离散化,然后用树状数组记录前后比i大或者比i小的元素,求出所有个数,分类讨论重合情况,减去重合的元素
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<fstream>
#include<set>
#include<memory>
#include<bitset>
#include<string>
#include<functional>
using namespace std;
typedef long long LL;
#define MAXN 500009
LL pre_max[MAXN], pre_min[MAXN], post_max[MAXN], post_min[MAXN];
LL a[MAXN], tmp[MAXN];
LL T[MAXN], n;
LL lowbit(LL x)
{
return x&(-x);
}
void update(LL x)
{
while (x <= MAXN)
{
T[x] += ;
x += lowbit(x);
}
}
LL getsum(LL x)
{
LL sum = ;
while (x > )
{
sum += T[x];
x -= lowbit(x);
}
return sum;
}
int main()
{
while (scanf("%lld", &n) != EOF)
{
memset(T, , sizeof(T));
for (LL i = ; i <= n; i++)
scanf("%lld", &a[i]);
memcpy(tmp, a, sizeof(a));
sort(tmp + , tmp + n + );
LL len = unique(tmp + , tmp + n + ) - tmp;
for (LL i = ; i <= n; i++)
a[i] = lower_bound(tmp + , tmp + len + , a[i]) - tmp;
for (LL i = ; i <= n; i++)
{
update(a[i]);
pre_min[i] = getsum(a[i] - );
pre_max[i] = i - getsum(a[i]);
}
LL sum1, sum2;
sum1 = sum2 = ;
for (int i = ; i <= n; i++)
{
post_min[i] = getsum(a[i] - ) - pre_min[i];
post_max[i] = n - getsum(a[i]) - pre_max[i];
sum1 += post_min[i];
sum2 += post_max[i];
}
LL ans = sum1*sum2;
for (int i = ; i <= n; i++)
{
ans -= pre_min[i] * pre_max[i];
ans -= pre_min[i] * post_min[i];
ans -= post_max[i] * pre_max[i];
ans -= post_max[i] * post_min[i];
}
printf("%lld\n", ans);
}
}

World is Exploding 树状数组+离散化的更多相关文章

  1. hdu 5792 World is Exploding 树状数组+离散化+容斥

    World is Exploding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  2. hdu4605 树状数组+离散化+dfs

    Magic Ball Game Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  3. BZOJ_5055_膜法师_树状数组+离散化

    BZOJ_5055_膜法师_树状数组+离散化 Description 在经历过1e9次大型战争后的宇宙中现在还剩下n个完美维度, 现在来自多元宇宙的膜法师,想偷取其中的三个维度为伟大的长者续秒, 显然 ...

  4. POJ 2299 【树状数组 离散化】

    题目链接:POJ 2299 Ultra-QuickSort Description In this problem, you have to analyze a particular sorting ...

  5. HDU 5792 World is Exploding(树状数组+离散化)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=5792 题意: 思路: lmin[i]:表示左边比第i个数小的个数. lmax[i]:表示左边比第i个 ...

  6. HDU 5792 L - World is Exploding 。容斥原理 + 树状数组 + 离散化

    题目,要求找出有多少对这样的东西,四个数,并且满足num[a]<num[b] &&num[c]>num[d] 要做这题,首先要懂得用树状数组,我设,下面的小于和大于都是严格 ...

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

  8. BZOJ-1227 虔诚的墓主人 树状数组+离散化+组合数学

    1227: [SDOI2009]虔诚的墓主人 Time Limit: 5 Sec Memory Limit: 259 MB Submit: 914 Solved: 431 [Submit][Statu ...

  9. POJ 2299 树状数组+离散化求逆序对

    给出一个序列 相邻的两个数可以进行交换 问最少交换多少次可以让他变成递增序列 每个数都是独一无二的 其实就是问冒泡往后 最多多少次 但是按普通冒泡记录次数一定会超时 冒泡记录次数的本质是每个数的逆序数 ...

随机推荐

  1. 微软最新的Web服务器Katana发布了版本3

    Katana 项目入门 Howard Dierking 当 ASP.NET 首次在 2002 年发布时,时代有所不同. 那时,Internet 仍处于起步阶段,大约有 5.69 亿用户,每个用户平均每 ...

  2. 掌握Spark机器学习库-07.6-线性回归实现房价预测

    数据集 house.csv 数据概览 代码 package org.apache.spark.examples.examplesforml import org.apache.spark.ml.fea ...

  3. iOS----轻松掌握AFN网络顶级框架

    AFN 一.什么是AFN 全称是AFNetworking,是对NSURLConnection的一层封装 虽然运行效率没有ASI高,但是使用比ASI简单 在iOS开发中,使用比较广泛 AFN的githu ...

  4. Xaml中的转义字符

    字符 转义字符 备注 & (ampersand) & 这个没什么特别的,几乎所有的地方都需要使用转义字符 > (greater-than character) > 在属性( ...

  5. [Windows Server 2012] 阿里云镜像购买和使用方法

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将演示:阿里云镜像购买 ...

  6. HDU_1856_带权并查集

    有10000000个同学,他们之间可能是直接朋友或者间接朋友,问最大的朋友圈有多少人. 一直觉得10000000的数组开不了,用map优化了一下,结果能开,且10000000也不会超时... #inc ...

  7. python 弹窗

    import ctypes message = ctypes.windll.user32.MessageBoxA(0,'message','tips',0)

  8. [python] 时间序列分析之ARIMA

    1 时间序列与时间序列分析 在生产和科学研究中,对某一个或者一组变量  进行观察测量,将在一系列时刻  所得到的离散数字组成的序列集合,称之为时间序列. 时间序列分析是根据系统观察得到的时间序列数据, ...

  9. 诊断:ORA-00376 & ORA-01110

    现象: Errors in file /path/of/diag/rdbms/prod/PROD/trace/PROD_ora_13447.trc: ORA-00376: 此时无法读取文件 61 OR ...

  10. vue 全局组件的注册

    第一步 在main.js里面 引入需要注册的组件例如: //引入组件 import header from  './components/header.vue' import footer from ...