树阵:

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

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

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. Delphi 中TWebBrowser的扩展控件TExWebBrowser

    主要扩展了3D界面.右键菜单.是否显示图片.是否支持JAVA等功能. 代码如下: unit ExtWebBrowser; interface uses Windows, SysUtils, Class ...

  2. 获取Exe文件版本信息的函数(使用GetFileVersionInfo得到TFileVersionInfo结构体,包含12项内容)

    Type   TFileVersionInfo   =   Record         FixedInfo:TVSFixedFileInfo;         {版本信息}         Comp ...

  3. Python逐块读取大文件行数的代码 - 为程序员服务

    Python逐块读取大文件行数的代码 - 为程序员服务 python数文件行数最简单的方法是使用enumerate方法,但是如果文件很大的话,这个方法就有点慢了,我们可以逐块的读取文件的内容,然后按块 ...

  4. IE6,IE7,IE8下报JS错误:expected identifier, string or number的原因及解决的方法

    今天在调试一个页面的时候遇到一个问题,在IE9下执行得非常好的脚本,在IE8里打开的时候弹出错误:expected identifier, string or number,依照经验,应该是定义对象的 ...

  5. MySQL错误:You are using safe update mode and you tried to update a table without a WHERE that uses a K

    转载自:http://blog.csdn.net/dragonpeng2008/article/details/7279590 Error: 1175 SQLSTATE: HY000 (ER_UPDA ...

  6. STL学习总结

    STL就是Standard Template Library,标准模板库.这可能是一个历史上最令人兴奋的工具的最无聊的术语.从根本上说,STL是一些"容器"的集合.这些" ...

  7. cocos2d-x项目101次相遇: Scenes , Director, Layers, Sprites

    cocos2d-x 101次相遇 / 文件夹  1   安装和环境搭建 -xcode  2   Scenes , Director, Layers, Sprites 3   建立图片菜单  4   在 ...

  8. 胡na娜、少年和恩师-写在甲午冬的仅仅言片语及感想

    [写在全新为移动互联网而生的Zoomla!逐浪CMS2 x2.1公布前] 恩师, 他来到这个乡村中学,带着自己的书.吉它和理想, 用自己最好的三年青春浇灌了这一代人, 在我辍学时,给我鼓舞,帮助我继续 ...

  9. 就是这么简单(续)!使用 RestAssuredMockMvc 测试 Spring MVC Controllers(转)

    接我前面一篇文章关于RestAssured测试Restful web service的, RestAssured还有一个功能, 使用RestAssuredMockMvc 单元测试你的Spring MV ...

  10. Indiegogo: An International Crowdfunding Platform to Raise Money

    Indiegogo: An International Crowdfunding Platform to Raise Money The world's funding platform. Fund ...