树阵:

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

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

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. 14.4.7 Configuring the Number of Background InnoDB IO Threads 配置 后台InnoDB IO Threads的数量

    14.4.7 Configuring the Number of Background InnoDB IO Threads 配置 后台InnoDB IO Threads的数量 InnoDB 使用bac ...

  2. C# Http以文件的形式上传文件

    以下的是上传的方法: // <summary> /// 将本地文件上传到指定的服务器(HttpWebRequest方法) /// </summary> /// <para ...

  3. Android获取设备採用的时间制式(12小时制式或24小时制式)

    /** * 获取设备採用的时间制式(12小时制式或者24小时制式) * 注意: * 在模拟器上获取的时间制式为空 */ private void getTime_12_24(Context conte ...

  4. codeforces 659C Tanya and Toys

    题目链接:http://codeforces.com/problemset/problem/659/C 题意: n是已经有的数字,m是可用的最大数字和 要求选自己没有的数字,且这些数字的数字和不能超过 ...

  5. C++primer原书中的一个错误(派生类using声明对基类权限的影响)

    在C++primer 第4版的 15章 15.2.5中有以下这样一段提示: "注解:派生类能够恢复继承成员的訪问级别,但不能使訪问级别比基类中原来指定的更严格或者更宽松." 在vs ...

  6. LeetCode总结 -- 树的性质篇

    树的性质推断是树的数据结构比較主要的操作,一般考到都属于非常easy的题目,也就是第一道入门题.面试中最好不能有问题,力求一遍写对.不要给面试官不论什么挑刺机会.LeetCode中关于树的性质有下面题 ...

  7. 《C/C++专项练习》 — (3)

    序 第三次C/C++专项.嗯,要抗住打击,继续加油~ 错题分析与总结 1 . 在64位系统中.有例如以下类: class A { public: void *p1; private: void *p2 ...

  8. js封装好的模仿qq消息弹窗代码

    在我们的日常开发中,或者生活中.常常须要用到弹出窗.这里我们就用js模拟一下qq消息一样的弹出窗. 直接贴代码: <!DOCTYPE html PUBLIC "-//W3C//DTD ...

  9. 创建并使用静态库(ar 命令)

     创建并使用静态库(ar 命令)            archive命令的功能是:创建或改动归档文件或者从归档文件里析取信息.能够简单的理解为一个打包工具,将成员文件依照一定的规则构建到.a文件里, ...

  10. dedecms 获取描述信息限制字数

    对于我刚刚刚开始对于获取到了描述的信息,但是有些字数简直是太多了,显示的样式不好看,所以我就希望限制字数,所以我来告诉你们获取描述信息限制字数的语法吧[field:description functi ...