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 ...
随机推荐
- cannot run program "git.exe":CreateProcess error=2
在使用android studio从git上check项目的时候报错cannot run program "git.exe":CreateProcess error=2 请检查下面 ...
- haproxy 中的http请求和https请求
use Mojolicious::Lite; use JSON qw/encode_json decode_json/; use Encode; no strict; use JSON; # /foo ...
- Loser tree in Python | Christan Christens
Loser tree in Python | Christan Christens Loser tree in Python I am taking an Advanced Data Structur ...
- 【Matlab编程】Matlab让电脑失而复得
在学校常常有同学电脑失窃,大抵都是粗细大意.据说iPhone手机失窃后能够获取小偷的照片,从而将照片找到.如今用matlab写一个程序使得当小偷使用电脑上网时,电脑自己主动将电脑前面的人的照片发到你指 ...
- 猎豹移动(金山网络)2015校园招聘(c++project师)
1.已知类MyString的原型为: class MyString { public: MyString(const char *str=NULL);//普通构造函数 MyString(const M ...
- HDU 4616 Game (搜索)、(树形dp)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4616 这道题目数据可能比较弱,搜索都可以AC,但是不敢写,哎…… 搜索AC代码: #include & ...
- cocos2d-x项目101次相遇: Scenes , Director, Layers, Sprites
cocos2d-x 101次相遇 / 文件夹 1 安装和环境搭建 -xcode 2 Scenes , Director, Layers, Sprites 3 建立图片菜单 4 在 ...
- 完整导出IntelliJ IDEA的快捷键
工欲善其事,必先利其器. 常常和代码打交道的人,熟练使用IDE快捷键那是必须的,由于快捷键能够把你从各种罗嗦事中解放出来.比方,假设没有快捷键,你就须要常常性的暂停快速执行的大脑,右手凭记忆摸到鼠标, ...
- Redis key 设计技巧
1: 把表名转换为key前缀 如, tag: 2: 第2段放置用于区分区key的字段--对应mysql中的主键的列名,如userid 3: 第3段放置主键值,如2,3,4...., a , b ,c ...
- 一次失败的刷题经历:[LeetCode]292之尼姆游戏(Nim Game)(转)
最近闲来无事刷LeetCode,发现这道题的Accept Rate还是挺高的,尝试着做了一下,结果悲剧了,把过程写下来,希望能长点记性.该题的描述翻译成中文如下: 你正在和你的朋友玩尼姆游戏(Nim ...