树状数组:
维护每一个数前面比它小的数的个数,和这个数后面比他大的数的个数
再枚举每个位置组合一下
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.
2.
3.
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
[Technical Specification]
1 <= T <= 100
1 <= n <= 50000
1 <=
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 BestCoder Round #23
/* *********************************************** Author :CKboss Created Time :2014年12月20日 星期六 21时38分00秒 File Name :HDOJ5147.cpp ************************************************ */ #include#include #include #include #include #include #include #include #include #include #include