• <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
            樹狀數組求逆序對的簡單應用。
            以下是我的代碼:
            #include<iostream>
            #include
            <algorithm>
            #include
            <cstdio>
            #include
            <cstring>
            #define lowbit(x) ((x)&(-(x)))
            using namespace std;
            const int kMaxn(1000007);

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

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

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

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

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

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

            int main()
            {
                
            //freopen("data.in","r",stdin);

                
            while(scanf("%d",&n)==1)
                {
                    
            for(int i=1;i<=n;i++)
                    {
                        r[i].num
            =i;
                        scanf(
            "%d",&r[i].value);
                    }
                    sort(r
            +1,r+n+1,cmp1);
                    
            for(int i=1;i<=n;i++)
                        r[i].weight
            =i;
                    sort(r
            +1,r+n+1,cmp2);

                    ans
            =0ll;
                    memset(bit,
            0,sizeof(bit));
                    
            for(int i=1;i<=n;i++)
                    {
                        ans
            +=i-Sum(r[i].weight-1)-1;
                        Add(r[i].weight,
            1);
                    }

                    cout
            <<ans<<endl;
                }

                
            return 0;
            }
            posted on 2011-08-01 09:55 lee1r 閱讀(583) 評論(0)  編輯 收藏 引用 所屬分類: 題目分類:數據結構
            久久久久久精品无码人妻| 久久精品国产精品亚洲毛片| 久久久国产精品网站| 免费精品99久久国产综合精品| 青青国产成人久久91网| 久久综合亚洲色HEZYO国产| 99精品国产免费久久久久久下载 | A级毛片无码久久精品免费| 久久久无码精品午夜| 狠狠色丁香久久婷婷综合| 亚洲天堂久久精品| 久久婷婷五月综合国产尤物app | 亚洲伊人久久成综合人影院 | 久久人人添人人爽添人人片牛牛| 亚洲AV无码1区2区久久| 久久播电影网| 99久久久国产精品免费无卡顿| 久久国产视屏| 亚洲国产成人久久精品动漫| 久久WWW免费人成一看片| 久久国产成人| 99久久亚洲综合精品成人| 久久精品毛片免费观看| 久久亚洲AV无码精品色午夜 | 久久精品成人| 青青草国产精品久久| 狠狠色丁香久久综合婷婷| 欧美精品久久久久久久自慰| 久久亚洲国产成人影院| 久久久久久国产精品无码下载| 日韩亚洲欧美久久久www综合网| 久久精品无码专区免费东京热| 免费精品国产日韩热久久| 欧美精品丝袜久久久中文字幕| 日本三级久久网| 99久久婷婷国产一区二区| 久久成人永久免费播放| 久久精品国产亚洲7777| 久久婷婷色香五月综合激情| 99久久精品国产一区二区| 久久夜色精品国产噜噜麻豆|