树阵:

每个号码的前面维修比其数数少,和大量的这后一种数比他的数字

再枚举每一个位置组合一下

Sequence II

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 121    Accepted Submission(s): 58

Problem Description
Long long ago, there is a sequence A with length n. All numbers in this sequence is no smaller than 1 and no bigger than n, and all numbers are different in this sequence.

Please calculate how many quad (a,b,c,d) satisfy:

1. 1≤a<b<c<d≤n

2. Aa<Ab

3. Ac<Ad
 
Input
The first line contains a single integer T, indicating the number of test cases.

Each test case begins with a line contains an integer n.

The next line follows n integers A1,A2,…,An.



[Technical Specification]

1 <= T <= 100

1 <= n <= 50000

1 <= Ai <=
n
 
Output
For each case output one line contains a integer,the number of quad.
 
Sample Input
1
5
1 3 2 4 5
 
Sample Output
4
 
Source
 

/* ***********************************************
Author :CKboss
Created Time :2014年12月20日 星期六 21时38分00秒
File Name :HDOJ5147.cpp
************************************************ */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map> using namespace std; typedef long long int LL; const int maxn=55000; int a[maxn];
int n; LL sum1[maxn],sum2[maxn];
int t1[maxn],t2[maxn]; int lowbit(int x) { return x&(-x); } /// 1 找比当前数小的 2 找比当前数大的 void init()
{
memset(sum1,0,sizeof(sum1));
memset(sum2,0,sizeof(sum2));
memset(t1,0,sizeof(t1));
memset(t2,0,sizeof(t2));
} void add(int kind,int p)
{
if(kind==1) for(int i=p;i<maxn;i+=lowbit(i)) t1[i]+=1;
else if(kind==2) for(int i=p;i;i-=lowbit(i)) t2[i]+=1;
} int sum(int kind,int p)
{
int ret=0;
if(kind==1) for(int i=p;i;i-=lowbit(i)) ret+=t1[i];
else if(kind==2) for(int i=p;i<maxn;i+=lowbit(i)) ret+=t2[i];
return ret;
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); int T_T;
scanf("%d",&T_T);
while(T_T--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",a+i); init(); /// from left to right
for(int i=1;i<=n;i++)
{
int ss=sum(1,a[i]);
sum1[i]=ss;
add(1,a[i]);
}
/// from right to left
for(int i=n;i>=1;i--)
{
int ss=sum(2,a[i]);
sum2[i]=sum2[i+1]+ss;
add(2,a[i]);
} LL ans=0;
for(int i=2;i<=n-1;i++)
{
/// X...i i+1...X
ans+=sum1[i]*sum2[i+1];
} cout<<ans<<endl;
} return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

HDOJ 5147 Sequence II 树阵的更多相关文章

  1. hdu 5147 Sequence II 树状数组

    Sequence II Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Prob ...

  2. hdu 5147 Sequence II (树状数组 求逆序数)

    题目链接 Sequence II Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. hdu 5147 Sequence II【树状数组/线段树】

    Sequence IITime Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem ...

  4. bestcoder#23 1002 Sequence II 树状数组+DP

    Sequence II Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. hdu 5147 Sequence II

    http://acm.hdu.edu.cn/showproblem.php?pid=5147 题意:问有多少个这样的四元组(a,b,c,d),满足条件是 1<=a<b<c<d; ...

  6. UVA 10869 - Brownie Points II(树阵)

    UVA 10869 - Brownie Points II 题目链接 题意:平面上n个点,两个人,第一个人先选一条经过点的垂直x轴的线.然后还有一个人在这条线上穿过的点选一点作垂直该直线的线,然后划分 ...

  7. HDU 5919 Sequence II 主席树

    Sequence II Problem Description   Mr. Frog has an integer sequence of length n, which can be denoted ...

  8. HDU 5919 Sequence II(主席树+逆序思想)

    Sequence II Time Limit: 9000/4500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) To ...

  9. 2016暑假多校联合---Rikka with Sequence (线段树)

    2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...

随机推荐

  1. NumPy简明教程

    源地址:http://blog.csdn.net/sunny2038/article/details/9002531 http://blog.csdn.net/sunny2038/article/de ...

  2. 第二章排错的工具:调试器Windbg(上)

    感谢博主 http://book.51cto.com/art/200711/59731.htm <Windows用户态程序高效排错>第二章主要介绍用户态调试相关的知识和工具.本文主要讲了排 ...

  3. java thread reuse(good)

    I have always read that creating threads is expensive. I also know that you cannot rerun a thread. I ...

  4. Everything You Wanted to Know About Machine Learning

    Everything You Wanted to Know About Machine Learning 翻译了理解机器学习的10个重要的观点,增加了自己的理解.这些原则在大部分情况下或许是这样,可是 ...

  5. VSTO 学习笔记(十二)自定义公式与Ribbon

    原文:VSTO 学习笔记(十二)自定义公式与Ribbon 这几天工作中在开发一个Excel插件,包含自定义公式,根据条件从数据库中查询结果.这次我们来做一个简单的测试,达到类似的目的. 即在Excel ...

  6. Keil - 编译错误总结 01

    Keil 编译 STM32project,出现下述错误. 并且.   Options for Target  -> Output   -  Browse  Information 选项无法勾选. ...

  7. [非官方]ArcGIS10.2 for Desktop扩展工具包——XTools Pro

    XTools Pro 是一套为ArcGIS平台设计的矢量空间分析. 形状转换和表管理扩展工具,大大增强了 ArcGIS 的功能,使用该工具能够提高 ArcGIS 用户的效率和性能. XTools Pr ...

  8. hdu3496(二维背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3496 题意:题意是 DuoDuo 想看n部电影,但是被要求最长能看的总时间数为 L,每部电影有他的时长 ...

  9. 项目中那些事|ListView中嵌套ListView问题

    要在一个ListView中放入另一个ListView,也即在一个ListView的每个 item 中放入另外一个ListView.但刚开始的时候,会发现放入的子ListView会显示不完全(我这里只显 ...

  10. Android-IA Power Manager (S3)

    Sleep and wake up