zoukankan      html  css  js  c++  java
  • 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多组数据 )
     1 #include <algorithm>
     2 #include <cstring>
     3 #include <cstdio>
     4 
     5 using namespace std;
     6 
     7 const int N(50000+5);
     8 #define LL long long
     9 int an1[N],an2[N];
    10 int n,a[N],tr[N];
    11 
    12 #define lowbit(x) (x&((~x)+1))
    13 inline void Update(int i,int x)
    14 {
    15     for(;i<=32770;i+=lowbit(i)) tr[i]+=x;
    16 }
    17 inline int Query(int x)
    18 {
    19     int ret=0;
    20     for(;x;x-=lowbit(x)) ret+=tr[x];
    21     return ret;
    22 }
    23 
    24 int main()
    25 {
    26     for(LL ans=0;~scanf("%d",&n);ans=0)
    27     {
    28         for(int i=1;i<=n;i++) scanf("%d",a+i);
    29         memset(tr,0,sizeof(tr));
    30         for(int i=1;i<=n;i++)
    31             an1[i]=Query(a[i]-1),Update(a[i],1);
    32         memset(tr,0,sizeof(tr));
    33         for(int i=n;i>=1;i--)
    34             an2[i]=Query(a[i]-1),Update(a[i],1);
    35         for(int i=1;i<=n;i++) ans=ans+(LL)an1[i]*an2[i];
    36         printf("%lld
    ",ans);
    37     }
    38     return 0;
    39 }
     
    ——每当你想要放弃的时候,就想想是为了什么才一路坚持到现在。
  • 相关阅读:
    八、总结
    第5章、Kafka监控
    十一、总结
    十、图形化的客户端和监控工具
    九、zookeeper四字监控命令
    八、zookeeper 开源客户端curator介绍
    七、Zookeeper原理
    六、zookeeper 事件监听机制
    五、zookeeper的javaApi
    四、zookeeper的Acl权限控制
  • 原文地址:https://www.cnblogs.com/Shy-key/p/7396766.html
Copyright © 2011-2022 走看看