HDOJ 5147 Sequence II 树阵
树阵:
每个号码的前面维修比其数数少,和大量的这后一种数比他的数字
再枚举每一个位置组合一下
Sequence II
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 121 Accepted Submission(s): 58
Please calculate how many quad (a,b,c,d) satisfy:
1. 1≤a<b<c<d≤n
2. Aa<Ab
3. Ac<Ad
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
1
5
1 3 2 4 5
4
/* ***********************************************
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 树阵的更多相关文章
- hdu 5147 Sequence II 树状数组
Sequence II Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Prob ...
- hdu 5147 Sequence II (树状数组 求逆序数)
题目链接 Sequence II Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 5147 Sequence II【树状数组/线段树】
Sequence IITime Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem ...
- bestcoder#23 1002 Sequence II 树状数组+DP
Sequence II Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 5147 Sequence II
http://acm.hdu.edu.cn/showproblem.php?pid=5147 题意:问有多少个这样的四元组(a,b,c,d),满足条件是 1<=a<b<c<d; ...
- UVA 10869 - Brownie Points II(树阵)
UVA 10869 - Brownie Points II 题目链接 题意:平面上n个点,两个人,第一个人先选一条经过点的垂直x轴的线.然后还有一个人在这条线上穿过的点选一点作垂直该直线的线,然后划分 ...
- HDU 5919 Sequence II 主席树
Sequence II Problem Description Mr. Frog has an integer sequence of length n, which can be denoted ...
- HDU 5919 Sequence II(主席树+逆序思想)
Sequence II Time Limit: 9000/4500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) To ...
- 2016暑假多校联合---Rikka with Sequence (线段树)
2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...
随机推荐
- VS2013中安装配置和使用Boost库
源地址:http://www.itnose.net/detail/6077953.html 时间:2014.07.24 地点:基地 ---------------------------------- ...
- Indy的TCPServer到底能支持多少个连接
最近一个项目,最开始使用IdTcpServer,在大压力测试的时候,只连接了800个多一点的客户端(每个客户端连接上之后每秒钟发送一个几十字节的报文,服务器应答).但是持续的时间不会超过10分钟,服务 ...
- Open Source RTOS
http://www.osrtos.com/ Name License Platforms Description Last updated FreeRTOS Modified GPL MSP ...
- HDU 3549 Flow Problem(有向边网络流)
九野的博客,转载请注明出处 :http://blog.csdn.net/acmmmm/article/details/11221561 题意:T个测试数据 下面n,m表示n个点m条有向带权边 m条边 ...
- ASI简单实现网络编程
使用iOS SDK中的HTTP网络请求API,相当的复杂,调用比較麻烦.ASIHTTPRequest 对CFNetwork API进行了封装.而且使用起来非常easy的一套API,在非常多比較老旧的项 ...
- oc深坑測试题及其答案
一.选择题(共80题,每题1分) 1. 不会立马使引用计数器改变的是: 答案:(C) A.release B.alloc C.autorelease D.retain 2. 在OC中类的接口声 ...
- [ACM] hdu 4405 Aeroplane chess (概率DP)
Aeroplane chess Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 ...
- [置顶] Bug 11775332 - cluvfy fails with PRVF-5636 with DNS response timeout error [ID 11775332.8]
Bug 11775332 cluvfy fails with PRVF-5636 withDNS response timeout error but error text is not clear ...
- java之jvm学习笔记四(安全管理器)
java之jvm学习笔记四(安全管理器) 前面已经简述了java的安全模型的两个组成部分(类装载器,class文件校验器),接下来学习的是java安全模型的另外一个重要组成部分安全管理器. 安全管理器 ...
- Hibernate学习之createSQLQuery与createQuery的区别及使用
hibernate中createQuery与createSQLQuery:前者用的hql语句进行查询,后者可以用sql语句查询,前者以hibernate生成的Bean为对象装入list返回,后者则是以 ...