HOJ——T 2275 Number sequence
2017-08-19 15:33
246 查看
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.
InputThe first line is an integer N (N <= 50000). The second line contains N integer(s): A1, A2, ..., An(0 <= Ai <= 32768).
OutputThere is only one number, which is the the number of different collocation.
Sample Input5 1 2 3 4 1Sample Output
6
对于每个数求出两侧的小于当前数的数量,乘法原理求和
(woc开longlong mmp多组数据 )
#include <algorithm> #include <cstring> #include <cstdio> using namespace std; const int N(50000+5); #define LL long long int an1 ,an2 ; int n,a ,tr ; #define lowbit(x) (x&((~x)+1)) inline void Update(int i,int x) { for(;i<=32770;i+=lowbit(i)) tr[i]+=x; } inline int Query(int x) { int ret=0; for(;x;x-=lowbit(x)) ret+=tr[x]; return ret; } int main() { for(LL ans=0;~scanf("%d",&n);ans=0) { for(int i=1;i<=n;i++) scanf("%d",a+i); memset(tr,0,sizeof(tr)); for(int i=1;i<=n;i++) an1[i]=Query(a[i]-1),Update(a[i],1); memset(tr,0,sizeof(tr)); for(int i=n;i>=1;i--) an2[i]=Query(a[i]-1),Update(a[i],1); for(int i=1;i<=n;i++) ans=ans+(LL)an1[i]*an2[i]; printf("%lld\n",ans); } return 0; }
相关文章推荐
- Hoj 2275 Number Sequence
- HOJ 2275 Number Sequence
- 树状数组题目总结三( 上)( HOJ 2275 Number sequence )
- HOJ 2275 Number sequence(树状数组)
- -----hoj 2275 Number sequence(树状数组)
- hoj 2275 Number Sequence
- HOJ 2275——Number sequence(树状数组)
- HOJ 2275 Number sequence(树状数组) 大于小于问题
- hoj 2275 Number sequence(树状数组)
- HOJ 2275 Number sequence(树状数组)
- HIT 2275 Number sequence
- HIT 2275 Number sequence
- hoj (2275)树状数组
- 求序列中满足Ai < Aj > Ak and i < j < k的组数 树状数组 HIT 2275 Number sequence
- hoj 2275 树状数组 水··不能int 64
- hoj 2275 Number sequence 树状数组解法
- HOJ 2728(POJ 1868) Antiarithmetic?
- hoj 1070 图的m可着色优化问题
- hdu 1711 Number Sequence
- Party --HOJ 11889