• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            心如止水
            Je n'ai pas le temps
            posts - 400,comments - 130,trackbacks - 0
            求逆序對個數。我是用離散化+樹狀數組做的。
            以下是我的代碼:
            /*
             * Author:  lee1r
             * Created Time:  2011/8/5 23:33:01
             * File Name: poj2299.cpp
             
            */
            #include
            <iostream>
            #include
            <sstream>
            #include
            <fstream>
            #include
            <vector>
            #include
            <list>
            #include
            <deque>
            #include
            <queue>
            #include
            <stack>
            #include
            <map>
            #include
            <set>
            #include
            <bitset>
            #include
            <algorithm>
            #include
            <cstdio>
            #include
            <cstdlib>
            #include
            <cstring>
            #include
            <cctype>
            #include
            <cmath>
            #include
            <ctime>
            #define L(x) ((x)<<1)
            #define R(x) (((x)<<1)+1)
            #define Half(x) ((x)>>1)
            #define lowbit(x) ((x)&(-(x)))
            using namespace std;
            const int kInf(0x7f7f7f7f);
            const double kEps(1e-8);
            typedef 
            long long int64;
            typedef unsigned 
            long long uint64;

            const int kMaxn(500007);

            struct Type
            {
                
            int id,value,num;
            };

            bool cmp1(const Type &a,const Type &b)
            {
                
            return a.value<b.value;
            }

            bool cmp2(const Type &a,const Type &b)
            {
                
            return a.id<b.id;
            }

            int n,bit[kMaxn];
            Type r[kMaxn];
            int64 ans;

            void Add(int x,int delta)
            {
                
            for(int i=x;i<=n;i+=lowbit(i))
                    bit[i]
            +=delta;
            }

            int Sum(int x)
            {
                
            int re(0);
                
            for(int i=x;i>0;i-=lowbit(i))
                    re
            +=bit[i];
                
            return re;
            }

            int main()
            {
                
            //freopen("data.in","r",stdin);
                
                
            while(scanf("%d",&n)==1 && n)
                {
                    
            for(int i=1;i<=n;i++)
                    {
                        scanf(
            "%d",&r[i].value);
                        r[i].id
            =i;
                    }
                    sort(r
            +1,r+n+1,cmp1);
                    
            for(int i=1;i<=n;i++)
                        r[i].num
            =i;
                    sort(r
            +1,r+n+1,cmp2);
                    
                    ans
            =0;
                    memset(bit,
            0,sizeof(bit));
                    
            for(int i=1;i<=n;i++)
                    {
                        Add(r[i].num,
            1);
                        ans
            +=i-Sum(r[i].num-1)-1;
                    }
                    
                    cout
            <<ans<<endl;
                }
                
                
            return 0;
            }
            posted on 2011-08-05 23:44 lee1r 閱讀(278) 評論(0)  編輯 收藏 引用 所屬分類: 題目分類:數據結構
            亚洲午夜久久久久久噜噜噜| 亚洲国产精品无码久久久久久曰| 精品熟女少妇av免费久久| 99久久免费国产特黄| 久久精品国产亚洲7777| 久久久久久国产精品美女| 亚洲AV无码久久精品狠狠爱浪潮 | 精品熟女少妇aⅴ免费久久| 精品无码人妻久久久久久| 久久精品人人做人人爽电影蜜月 | 免费国产99久久久香蕉| 亚洲精品99久久久久中文字幕| 粉嫩小泬无遮挡久久久久久 | 久久综合亚洲欧美成人| 麻豆国内精品久久久久久| 精品国产福利久久久| 久久只有这精品99| 久久精品国产色蜜蜜麻豆| 精品永久久福利一区二区| 久久人人爽人人爽人人爽 | 久久久青草青青国产亚洲免观| 久久不见久久见免费视频7| 一本色综合久久| 激情综合色综合久久综合| 国产精品免费看久久久| 怡红院日本一道日本久久 | 99久久99久久久精品齐齐| 成人亚洲欧美久久久久| 国产高潮久久免费观看| 久久精品国产亚洲AV大全| 色8激情欧美成人久久综合电| 久久久91精品国产一区二区三区 | 午夜福利91久久福利| 大蕉久久伊人中文字幕| 91久久成人免费| 一级做a爰片久久毛片人呢| 人人狠狠综合久久亚洲婷婷| 色综合久久88色综合天天| 国产一区二区精品久久岳| 久久国产精品波多野结衣AV| 久久这里有精品视频|