HOJ2275 Number sequence
Number sequence
My Tags | tag=&type=or" style="margin:0px; padding:0px; color:rgb(27,87,177); text-decoration:none"> (Edit) |
---|
Source : id=SCU%20Programming%20Contest%202006%20Final" style="margin:0px; padding:0px; color:rgb(27,87,177); text-decoration:none">SCU Programming |
|||
Time limit : 1 sec | Memory limit : 64 M |
Submitted : 1632, Accepted : 440
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
这题能够用树状数组做,开两个一维的树状数组分别记录当前点前面的比这点小的个数和后面比这点大的个数。
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define maxn 50005
#define ll long long
int b1[maxn],b2[maxn],a[maxn];
int lowbit(int x){
return x&(-x);
}
void update1(int pos,int num)
{
while(pos<=maxn){
b1[pos]+=num;pos+=lowbit(pos);
}
}
int getsum1(int pos)
{
int num=0;
while(pos>0){
num+=b1[pos];pos-=lowbit(pos);
}
return num;
} void update2(int pos,int num)
{
while(pos<=maxn){
b2[pos]+=num;pos+=lowbit(pos);
}
}
int getsum2(int pos)
{
int num=0;
while(pos>0){
num+=b2[pos];pos-=lowbit(pos);
}
return num;
} int main()
{
int n,m,i,j;
ll num=0;
while(scanf("%d",&n)!=EOF)
{
memset(b1,0,sizeof(b1));
memset(b2,0,sizeof(b2));
for(i=1;i<=n;i++){
scanf("%d",&a[i]);
a[i]++;
if(i==1){
update1(a[i],1);continue;
}
update2(a[i],1);
}
num=0;
for(i=2;i<=n-1;i++){
num+=getsum1(a[i]-1)*getsum2(a[i]-1);
update1(a[i],1);
update2(a[i],-1);
}
printf("%lld\n",num);
}
return 0;
}
HOJ2275 Number sequence的更多相关文章
- 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 ...
- Number Sequence 分类: HDU 2015-06-19 20:54 10人阅读 评论(0) 收藏
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- HDU 1711 Number Sequence(数列)
HDU 1711 Number Sequence(数列) Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
随机推荐
- ExtJs4 笔记(1) ExtJs大比拼JQuery:Dom文档操作
现在主流的JS框架要数ExtJs和JQuery应用的比较广泛.JQuery属于轻量级的,一般做网站应用比较常见,可见块头小的优势.ExtJs比较庞大,它除了对基本的JS语法和HTML DOM操作方式的 ...
- Android:通知栏的使用
非常久没有使用Android的通知功能了,今天把两年前的代码搬出来一看.发现非常多方法都废弃了,代码中各种删除线看的十分不爽.于是乎,打开Google,查看官方文档.学习最新的发送通知栏消息的方法. ...
- Andy's First Dictionary
Description Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy ...
- ruby on rails创建的页面訪问很慢
ruby on rails创建的页面訪问很慢 用rvm安装的ruby1.9.3 解决:cd ~/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/webrick v ...
- 【IOS工具类】获得设备唯一标识(兼容IOS5,6,7)
UIDevice+IdentifierAddition.h: #import <Foundation/Foundation.h> @interface UIDevice (Identifi ...
- 成都Java培训机构太多,该如何选择呢?
Java培训的势头愈发火热.越来越多的人看到了Java培训的前途所在,可是最好的Java培训机构是哪家呢?如何推断一家Java培训机构的专业性呢?140610lscs" target=&qu ...
- [置顶] 如何在Python IDLE中调试Python代码?
好久没有用Python了,居然忘记了怎么在Python IDLE中调试Python代码.百度了一下,然后还是写下来吧,以免以后又忘记了. 1. Set break point in the sourc ...
- 离别·伤
天边露出尖尖的小月 青涩似梦 一点萤火虫落在时光的蘋 搜索 若然恍惚 莺归晚巢 日隐西山 至此予你别过 未曾听你轻启朱唇 未曾见你合身回眸 风,走过紫罗兰花 淡淡的香绕过你的长发 ...
- 命令模式在MVC框架中的应用
事实上在项目开发中,我们使用了大量的设计模式,不过这些设计模式都封装在框架中了,假设你想要不只局限于简单的使用,就应该深入了解框架的设计思路. 在MVC框架中,模式之中的一个就是命令模式,先来看看模式 ...
- C++操作符operator的另一种用法
http://blog.csdn.net/memewry/article/details/7833314 参考地址 今天在程序员面试宝典上看到这样一道题目: A C++ developer want ...