bestcoder#23 1002 Sequence II 树状数组+DP
Sequence II
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 652 Accepted Submission(s): 164
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
5
1 3 2 4 5
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 50005+100
const int inf=0x7fffffff; //无限大
int a[maxn];
ll dp_qmin[maxn];
ll dp2[maxn],sum[maxn];
ll dp_hmax[maxn];
int n;
long long ans; int lowbit(int x)
{
return x&(-x);
} void update(int x,ll val)
{
while(x <= n)
{
sum[x] += val;
x += lowbit(x);
}
} long long query(int x)
{
long long s=;
while(x>)
{
s += sum[x];
x -= lowbit(x);
}
return s;
} int main()
{
//freopen("D.txt","r",stdin);
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
dp_qmin[i]=;
dp2[i]=;
dp_hmax[i]=;
sum[i]=;
}
for(int i=;i<=n;i++){
ll t=query(a[i]-);
dp_qmin[i]=t;
dp_hmax[i]=(n-i)-(a[i]--t);
//printf("i=%d dpmin=%lld dpmax=%lld\n",i,dp_qmin[i],dp_hmax[i]);
update(a[i],);
}
ll ans=;
ll sum1=;
sum1=dp_qmin[]+dp_qmin[];
for(int i=;i<=n-;i++)
{
ans+=sum1*dp_hmax[i];
sum1+=dp_qmin[i];
}
printf("%I64d\n",ans);
}
}
bestcoder#23 1002 Sequence II 树状数组+DP的更多相关文章
- 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) ...
- “浪潮杯”第九届山东省ACM大学生程序设计竞赛(重现赛)E.sequence(树状数组求逆序对(划掉))
传送门 E.sequence •题意 定义序列 p 中的 "good",只要 i 之前存在 pj < pi,那么,pi就是 "good": 求删除一个数, ...
- POJ 2464 Brownie Points II --树状数组
题意: 有点迷.有一些点,Stan先选择某个点,经过这个点画一条竖线,Ollie选择一个经过这条直接的点画一条横线.Stan选这两条直线分成的左下和右上部分的点,Ollie选左上和右下部分的点.Sta ...
- HDU 5273 Dylans loves sequence【 树状数组 】
题意:给出n个数,再给出q个询问,求L到R的逆序对的个数 先自己写的时候,是每次询问都重新插入来求sum(r)-sum(l) 果断T 后来还是看了别人的代码---- 预处理一下,把所有可能的区间的询问 ...
- 【USACO】奶牛抗议 树状数组+dp
题目描述 约翰家的 N 头奶牛正在排队游行抗议.一些奶牛情绪激动,约翰测算下来,排在第 i 位的奶牛 的理智度为 A i ,数字可正可负. 约翰希望奶牛在抗议时保持理性,为此,他打算将这条队伍分割成几 ...
- CodeForces - 314C Sereja and Subsequences (树状数组+dp)
Sereja has a sequence that consists of n positive integers, a1, a2, ..., an. First Sereja took a pie ...
- [Codeforces261D]Maxim and Increasing Subsequence——树状数组+DP
题目链接: Codeforces261D 题目大意:$k$次询问,每次给出一个长度为$n$的序列$b$及$b$中的最大值$maxb$,构造出序列$a$为$t$个序列$b$连接而成,求$a$的最长上升子 ...
- hdu 3030 Increasing Speed Limits (离散化+树状数组+DP思想)
Increasing Speed Limits Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java ...
随机推荐
- httpd功能配置之虚拟主机【转】
apache默认使用80端口提供服务,使用主服务器配置的话,一台物理机只能提供一个站点服务:可以使用虚拟主机方式提供不同的访问,以实现一台主机提供多站点服务. 虚拟主机的实现方式有三种:基于端口.基于 ...
- 深入理解MySQL的并发控制、锁和事务【转】
本文主要是针对MySQL/InnoDB的并发控制和加锁技术做一个比较深入的剖析,并且对其中涉及到的重要的概念,如多版本并发控制(MVCC),脏读(dirty read),幻读(phantom read ...
- VirtualBox上安装CentOS-7(Minimal)
Windows 10家庭中文版,VirtualBox 5.2.12,CentOS 7(Minimal版), 因为听到大家在谈论CentOS,阿里云上也有CentOS,CentOS还是Red Hat出品 ...
- InnoDB锁问题
InnoDB锁问题 InnoDB与MyISAM的最大不同有两点:一是支持事务(TRANSACTION):二是采用了行级锁.行级锁与表级锁本来就有许多不同之处,另外,事务的引入也带来了一些新问题.下面我 ...
- java基础59 JavaScript运算符与控制流程语句(网页知识)
1.JavaScript运算符 1.1.加减乘除法 加法:+(加法,连接符,正数) true是1,false是0 减法:- 乘法:* 除法:/ 1.2.比较运算符 ...
- 洛谷P1242 新汉诺塔
传送门啦 首先要将第n个盘子从x到y,那么就要把比n小的盘子全部移到6-x-y,然后将n移到y 仔细想想:6代表的是3根初始柱,3根目标柱. 6-(x+y) 便是我们的中转柱了,因为到这个位置是最优的 ...
- 异步消息框架netty
Netty-WebSocket长连接推送服务 http://blog.csdn.net/z69183787/article/details/52505249 http://blog.csdn.net/ ...
- dedecms调用文章列表第一篇和下面几篇不同的方法
{dede:arclist row=1 orderby=pubdate infolen=60 limit=0,1} <li class="dot1"><img s ...
- 查找Mysql慢查询Sql语句
一.MySQL数据库有几个配置选项可以帮助我们及时捕获低效SQL语句 1,slow_query_log 这个参数设置为ON,可以捕获执行时间超过一定数值的SQL语句. 2,long_query_tim ...
- 大数据统计分析平台之三、Kibana安装和使用
kibana安装 1.到官网下载kibana: cd /usr/local/software wget https://artifacts.elastic.co/downloads/kibana/ki ...