题意:给定 n 个数,让你数出 a < b && c < d && a != b != c != d  && Aa < Ab && Ac > Ad。

析:首先,给的数太大了,先要进行离散化处理,然后先算出Aa < Ab 和  Ac > Ad。这可以用树状数组解决,一个正向的,一个反向,同时再求出四种数,然后减去,就好了。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
//#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define all 1,n,1
#define FOR(x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e15;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 5e4 + 100;
const int mod = 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
} vector<int> v; int a[maxn];
int sum[2][maxn<<1]; int lowbit(int x){ return -x&x; } void add(int pos, int x){
while(x <= n){
++sum[pos][x];
x += lowbit(x);
}
} int query(int pos, int x){
int ans = 0;
while(x){
ans += sum[pos][x];
x -= lowbit(x);
}
return ans;
} int getPos(int x){
return lower_bound(v.begin(), v.end(), x) - v.begin();
} int b[maxn], c[maxn], d[maxn], e[maxn]; int main(){
while(scanf("%d", &n) == 1){
v.cl; ms(sum, 0);
v.pb(-1);
for(int i = 0; i < n; ++i){
scanf("%d", a+i);
v.pb(a[i]);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end()); LL ans = 0;
LL tmp1 = 0, tmp2 = 0;
LL tmp3 = 0, tmp4 = 0, tmp5 = 0;
for(int i = 0; i < n; ++i){
int pos = getPos(a[i]);
b[i] = query(0, pos-1);
tmp1 += b[i]; // min
c[i] = i - query(0, pos);
tmp3 += (LL)b[i] * c[i];
add(0, pos);
} for(int i = n-1; i >= 0; --i){
int pos = getPos(a[i]);
d[i] = query(1, pos-1);
tmp2 += d[i]; //right min
e[i] = (n-i-1) - query(1, pos);
tmp4 += (LL)d[i] * e[i];
//tmp4 += (n-i-1) - query(1, pos); // right max
add(1, pos);
} LL tmp6 = 0;
for(int i = 0; i < n; ++i){
tmp5 += (LL)c[i] * e[i];
tmp6 += (LL)b[i] * d[i];
} ans = tmp1 * tmp2 - tmp3 - tmp4 - tmp5 - tmp6;
printf("%I64d\n", ans); }
return 0;
}

  

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

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

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

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

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

  3. HDU 6318 - Swaps and Inversions - [离散化+树状数组求逆序数][杭电2018多校赛2]

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=6318 Problem Description Long long ago, there was an ...

  4. hdu 3030 Increasing Speed Limits (离散化+树状数组+DP思想)

    Increasing Speed Limits Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

  5. HDU 5862 Counting Intersections(离散化 + 树状数组)

    Counting Intersections Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/ ...

  6. HDU 5862 Counting Intersections(离散化+树状数组)

    HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...

  7. hdu 3015 Disharmony Trees (离散化+树状数组)

    Disharmony Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. HDU 6318.Swaps and Inversions-求逆序对-线段树 or 归并排序 or 离散化+树状数组 (2018 Multi-University Training Contest 2 1010)

    6318.Swaps and Inversions 这个题就是找逆序对,然后逆序对数*min(x,y)就可以了. 官方题解:注意到逆序对=交换相邻需要交换的次数,那么输出 逆序对个数 即可. 求逆序对 ...

  9. CodeForces 540E - Infinite Inversions(离散化+树状数组)

    花了近5个小时,改的乱七八糟,终于A了. 一个无限数列,1,2,3,4,...,n....,给n个数对<i,j>把数列的i,j两个元素做交换.求交换后数列的逆序对数. 很容易想到离散化+树 ...

随机推荐

  1. Window下MySql 5.6 安装后内存占用很高的问题

    Window下MySql 5.6 安装后内存占用很高的问题 刚刚准备玩一把mysql,初学者 环境是window 7和window sever 2008, mysql是最新的5.6, 发现的问题是安装 ...

  2. 【转】C#命名规范

    原文地址:http://www.jb51.net/article/57163.htm 本文详细汇总了C#常用的命名规则.分享给大家供大家参考.具体如下: Pascal 规则每个单词开头的字母大写(如 ...

  3. 机器学习,数据挖掘,统计学,云计算,众包(crowdsourcing),人工智能,降维(Dimension reduction)

    机器学习 Machine Learning:提供数据分析的能力,机器学习是大数据时代必不可少的核心技术,道理很简单:收集.存储.传输.管理大数据的目的,是为了“利用”大数据,而如果没有机器学习技术分析 ...

  4. css伪类(Pseudo-classes)

    简介:伪类(Pseudo classes)是选择符的螺栓,用来指定一个或者与其相关的选择符的状态.它们的形式是selector:pseudo class { property: value; },简单 ...

  5. 关于java中的OutOfMemory种类和解决方法

    1.OutOfMemory的三种情况 1) 永久区溢出 Exception in thread "main" java.lang.OutOfMemoryError: PermGen ...

  6. ui-router 留存

    学习 ui-router - 路由控制 022014年01月 参考原文:https://github.com/angular-ui/ui-router/wiki/URL-Routing 在你的应用中大 ...

  7. failed to open stream: No such file or directory 报错解决方法

    1.首先检查是否是文件名错误(比如有空格):是否因为路径不完整(比如缺少http://,或者缺少文件扩展名.doc等): 2.若是在本地中文名文件打开报错,我就是因为编码不一致导致: Windows中 ...

  8. 前端开发之JavaScript HTML DOM理论篇二

    主要内容: 1.HTML DOM元素 2.HTML DOM事件 一.DOM元素 主要操作有添加.删除和替换HTML元素 1.创建新的HTML元素  (1)方法一: appendChild() 追加 如 ...

  9. 前端开发之CSS篇四

    一.相对定位 二.绝对定位 三.固定定位 四.z-index 前言 定位有三种:1.相对定位 2.绝对定位 3.固定定位 这三种定位,每种都暗藏玄机,所以要每个单独剖析. 1️⃣   相对定位 1.三 ...

  10. 蓝桥杯算法训练 java算法 表达式求值

    问题描述 输入一个只包含加减乖除和括号的合法表达式,求表达式的值.其中除表示整除. 输入格式 输入一行,包含一个表达式. 输出格式 输出这个表达式的值. 样例输入 1-2+3*(4-5) 样例输出 - ...