• <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)  編輯 收藏 引用 所屬分類: 題目分類:數據結構
            久久久久久伊人高潮影院| 麻豆成人久久精品二区三区免费 | 欧美精品一区二区精品久久 | 99re久久精品国产首页2020| 激情伊人五月天久久综合| 国产 亚洲 欧美 另类 久久| 久久91这里精品国产2020| 久久久无码精品亚洲日韩京东传媒 | 久久精品国产精品亚洲毛片| www亚洲欲色成人久久精品| 大香伊人久久精品一区二区| 精品免费tv久久久久久久| 国内精品伊人久久久久妇| 久久精品国产清高在天天线| 中文字幕精品久久久久人妻| 一本伊大人香蕉久久网手机| 久久天天躁狠狠躁夜夜躁2014| 久久香蕉国产线看观看乱码| 国内精品久久久久影院老司 | 99精品国产综合久久久久五月天| 一本久久a久久精品综合夜夜| 久久综合久久自在自线精品自 | 一本色综合网久久| 久久人人爽人人澡人人高潮AV| 91精品国产综合久久精品| 亚洲精品乱码久久久久久中文字幕| 久久香蕉国产线看观看精品yw| 欧美无乱码久久久免费午夜一区二区三区中文字幕 | 国产精品久久久久AV福利动漫| 国产精品中文久久久久久久| 久久艹国产| 色天使久久综合网天天| 超级碰久久免费公开视频| 97久久精品无码一区二区天美| 亚洲狠狠婷婷综合久久蜜芽| 亚洲国产一成人久久精品| 亚洲av伊人久久综合密臀性色| 久久国产免费直播| 久久精品国产亚洲AV麻豆网站| 精品久久久久久久久午夜福利| 精品久久8x国产免费观看|