<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      HDU 2492 Ping pong (樹狀數組)

      題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=2492

                                         Ping pong

       

      Problem Description

      N(3<=N<=20000) ping pong players live along a west-east street(consider the street as a line segment). 

      Each player has a unique skill rank. To improve their skill rank, they often compete with each other. If two players want to compete, they must choose a referee among other ping pong players and hold the game in the referee's house. For some reason, the contestants can’t choose a referee whose skill rank is higher or lower than both of theirs.

      The contestants have to walk to the referee’s house, and because they are lazy, they want to make their total walking distance no more than the distance between their houses. Of course all players live in different houses and the position of their houses are all different. If the referee or any of the two contestants is different, we call two games different. Now is the problem: how many different games can be held in this ping pong street? 

      Input

      The first line of the input contains an integer T(1<=T<=20), indicating the number of test cases, followed by T lines each of which describes a test case.


      Every test case consists of N + 1 integers. The first integer is N, the number of players. Then N distinct integers a1, a2 … aN follow, indicating the skill rank of each player, in the order of west to east. (1 <= ai <= 100000, i = 1 … N).

      Output

      For each test case, output a single line contains an integer, the total number of different games. 

      Sample Input

      1

      3 1 2 3

      Sample Output

      1

       

      話不多說 直接上代碼

      解釋都在代碼中標注了

       1 #include<stdio.h>
       2 #include<string.h>
       3 #define size 100100
       4 int n,c[size],x1[size],x2[size],y1[size],y2[size],a[size];
       5 
       6 int Lowbit(int k)
       7 {
       8     return (k&-k);
       9 }
      10 void update(int pos,int num)
      11 {
      12     while(pos<size)//重要  是size  而不是<=n
      13     {
      14         c[pos]+=num;
      15         pos+=Lowbit(pos);
      16     }
      17 }
      18 int sum(int pos)
      19 {
      20     int s=0;
      21     while(pos>0)
      22     {
      23         s+=c[pos];
      24         pos-=Lowbit(pos);
      25     }
      26     return s;
      27 }
      28 
      29 
      30 
      31 int main()
      32 {
      33        int i,cas;
      34        scanf("%d",&cas);
      35        while(cas--)
      36        {
      37            memset(c,0,sizeof(c));
      38            scanf("%d",&n);
      39            for(i=1;i<=n;i++) 
      40            {
      41                scanf("%d",&a[i]);   
      42                int k1; 
      43                k1=sum(a[i]);
      44                x1[i]=k1; //輸入的i個數中 有k1個比a[i]小
      45                x2[i]=i-1-k1; //輸入的i個數中 有k1個比a[i]大
      46                update(a[i],1);
      47            }
      48            memset(c,0,sizeof(c));
      49            int j=1;//代表現在輸入的數的個數 
      50            for(i=n;i>=1;i--,j++) 
      51            {
      52                  int k1;
      53                  k1=sum(a[i]);
      54                  y1[i]=k1;//輸入a[i]后輸入的那些數中有多少個比a[i]小的
      55                  y2[i]=j-1-k1; //輸入a[i]后輸入的那些數中有多少個比a[i]大的
      56                  update(a[i],1);
      57            }
      58            __int64 ans=0;
      59            for(i=1;i<=n;i++)
      60            {
      61               // printf("x1[%d]=%d x2[%d]=%d y1[%d]=%d  y2[%d]=%d\n",i,x1[i],i,x2[i],i,y1[i],i,y2[i]);
      62               ans+=x1[i]*y2[i]+x2[i]*y1[i];
      63                // ans+=x1[i]*x2[i];
      64            }
      65            printf("%I64d\n",ans);
      66        }
      67 
      68 }
      View Code

       

       

       

      posted @ 2014-08-15 19:41  四十四次日落  Views(406)  Comments(0)    收藏  舉報
      主站蜘蛛池模板: 亚洲精品成人片在线观看精品字幕| 乱子伦视频在线看| 日韩免费美熟女中文av| 国产乱码一区二区三区| 在线精品国精品国产不卡| 通许县| 国产第一区二区三区精品| 人妻少妇精品中文字幕| 2019国产精品青青草原| 精品国产一区二区三区av色诱| 亚洲另类无码一区二区三区| 亚洲欧洲日产国无高清码图片| 成人国产精品日本在线观看| 国产99在线 | 欧美| 乱色精品无码一区二区国产盗| 国产精品十八禁在线观看| 无套内谢少妇一二三四| AV老司机色爱区综合| 深夜av在线免费观看| 亚洲av综合av一区| 国产高清在线精品一区二区三区| 碌曲县| 国产AV福利第一精品| 国产三级a三级三级| 中文字幕av一区二区三区| 最新的国产成人精品2020| 草裙社区精品视频播放| 国产亚洲精品成人av在线| 2021亚洲国产精品无码| 成人拍拍拍无遮挡免费视频| 欧美亚洲另类 丝袜综合网| 亚洲人成色77777| 中文字幕在线精品人妻| 奎屯市| 久久精品波多野结衣| xxxxbbbb欧美残疾人| 久久精品国产午夜福利伦理| 一本色道国产在线观看二区| 久久一日本综合色鬼综合色| 成人精品大片—懂色av| 亚洲aⅴ无码专区在线观看春色|