HOJ——T 2275 Number sequence
http://acm.hit.edu.cn/hoj/problem/view?id=2275
Source : SCU Programming Contest 2006 Final | |||
Time limit : 1 sec | Memory limit : 64 M |
Submitted : 1864, Accepted : 498
Given a number sequence which has N element(s), please calculate the number of different collocation for three number Ai, Aj, Ak, which satisfy that Ai < Aj > Ak and i < j < k.
Input
The first line is an integer N (N <= 50000). The second line contains N integer(s): A1, A2, ..., An(0 <= Ai <= 32768).
Output
There is only one number, which is the the number of different collocation.
Sample Input
5
1 2 3 4 1
Sample Output
6 对于每个数求出两侧的小于当前数的数量,乘法原理求和
(woc开longlong mmp多组数据 )
#include <algorithm>
#include <cstring>
#include <cstdio> using namespace std; const int N(+);
#define LL long long
int an1[N],an2[N];
int n,a[N],tr[N]; #define lowbit(x) (x&((~x)+1))
inline void Update(int i,int x)
{
for(;i<=;i+=lowbit(i)) tr[i]+=x;
}
inline int Query(int x)
{
int ret=;
for(;x;x-=lowbit(x)) ret+=tr[x];
return ret;
} int main()
{
for(LL ans=;~scanf("%d",&n);ans=)
{
for(int i=;i<=n;i++) scanf("%d",a+i);
memset(tr,,sizeof(tr));
for(int i=;i<=n;i++)
an1[i]=Query(a[i]-),Update(a[i],);
memset(tr,,sizeof(tr));
for(int i=n;i>=;i--)
an2[i]=Query(a[i]-),Update(a[i],);
for(int i=;i<=n;i++) ans=ans+(LL)an1[i]*an2[i];
printf("%lld\n",ans);
}
return ;
}
HOJ——T 2275 Number sequence的更多相关文章
- HOJ 2275 Number sequence
题意:问你有多少个序列满足Ai < Aj > Ak and i < j < k. 思路:对每个数求它之前和之后分别有多少个个数比它小,两边相乘.最后求和.具体实现先用树状数组正 ...
- HIT 2275 Number sequence
点击打开HIT 2275 思路: 树状数组 分析: 1 题目要求的是总共的搭配方式,满足Ai < Aj > Ak.并且i j k不同 2 我们开两个树状数组,第一个在输入的时候就去更新.然 ...
- HDU 1005 Number Sequence
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- POJ 1019 Number Sequence
找规律,先找属于第几个循环,再找属于第几个数的第几位...... Number Sequence Time Limit: 1000MS Memory Limit: 10000K Total Submi ...
- HDOJ 1711 Number Sequence
Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Number Sequence
Number Sequence A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) ...
- [AX]AX2012 Number sequence framework :(三)再谈Number sequence
AX2012的number sequence framework中引入了两个Scope和segment两个概念,它们的具体作用从下面序列的例子说起. 法国/中国的法律要求财务凭证的Journal nu ...
- KMP - HDU 1711 Number Sequence
Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 1005:Number Sequence(水题)
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
随机推荐
- JNI之——'cl' 不是内部或外部命令,也不是可执行的程序或批处理文件
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46604315 问题的出现: 今天卸载了VS2010,重装vs2008后.发 ...
- Android微信智能心跳方案 Android微信智能心跳方案
原文地址: http://mp.weixin.qq.com/s?__biz=MzAwNDY1ODY2OQ==&mid=207243549&idx=1&sn=4ebe4beb81 ...
- 6. Intellij Idea 2017创建web项目及tomcat部署实战
转自:https://www.cnblogs.com/shindo/p/7272646.html 相关软件:Intellij Idea2017.jdk16.tomcat7 Intellij Idea直 ...
- Conditionals
1. Modulus operator (%) The modulus operator works on integers and yields the remainder when the fir ...
- Metasploit的攻击实例讲解----ms10_046快捷方式图标漏洞
不多说,直接上干货! 准备工具 1.Kali linux 2016.2(Rolling)系统 IP: 192.168.1.103 2.受害者机子(windows XP系统) IP: 10.10 ...
- Maven项目:Plugin execution not covered by lifecycle configuration 解决方案
这个是eclipse中配置文件pom.xml报的错.具体错误信息: Plugin execution not covered by lifecycle configuration: org.apach ...
- Android RecyclerView实现横向滚动
我相信很久以前,大家在谈横向图片轮播是时候,优先会选择具有HorizontalScrollView效果和ViewPager来做,不过自从Google大会之后,系统为我们提供了另一个控件Recycler ...
- C# 引用DLL版本冲突
已解决,到官网上下载旧key版本,然后再重定向即可. 手动引用两个版本的DLL错误的原因是我 publicKeyToken 大小写的问题(竟然没校验~~) 但我想不明白,这样搞如果依赖一多的话,甚至那 ...
- webpack(构建一个前端项目)详解--升级
升级一个正式的项目结构 分离webpack.config.js文件: 新建一个webpack.config.base.js任何环境依赖的wbpack //public webpack const pa ...
- C#中Dictionary排序方式
转载自:https://www.cnblogs.com/5696-an/p/5625142.html 自定义类: https://files.cnblogs.com/files/xunhanliu/d ...