• <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
            用三個樹狀數(shù)組維護一下:比a[i]小的數(shù)有多少、前i個數(shù)之和是多少、比a[i]小的數(shù)之和是多少。
            以下是我的代碼:
            /*
             * Author:  lee1r
             * Created Time:  2011/8/2 9:33:01
             * File Name: hdu2838.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 lowbit(x) ((x)&(-(x)))
            using namespace std;
            typedef 
            long long int64;
            typedef unsigned 
            long long uint64;
            const int kMaxn(100007);

            int n;
            int64 ans,bit[kMaxn],bit2[kMaxn],bit3[kMaxn];

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

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

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

                
            while(scanf("%d",&n)==1)
                {
                    ans
            =0;
                    memset(bit,
            0,sizeof(bit));
                    memset(bit2,
            0,sizeof(bit2));
                    memset(bit3,
            0,sizeof(bit3));

                    
            for(int i=1;i<=n;i++)
                    {
                        
            int t;
                        scanf(
            "%d",&t);
                        Add(bit,t,
            1);
                        Add(bit2,i,t);
                        Add(bit3,t,t);
                        ans
            +=(i-Sum(bit,t-1)-1)*t;
                        ans
            +=Sum(bit2,i-1);
                        ans
            -=Sum(bit3,t-1);
                    }

                    cout
            <<ans<<endl;
                }

                
            return 0;
            }
            posted on 2011-08-02 10:23 lee1r 閱讀(490) 評論(0)  編輯 收藏 引用 所屬分類: 題目分類:數(shù)據(jù)結(jié)構(gòu)
            久久婷婷五月综合色奶水99啪| 久久亚洲精品无码观看不卡| 日产精品久久久一区二区| 久久久久久午夜成人影院| 精品久久人妻av中文字幕| 精品久久久久中文字幕一区| 久久无码专区国产精品发布| 久久线看观看精品香蕉国产| 久久久久人妻精品一区三寸蜜桃| 色综合久久久久综合体桃花网| 精品久久人人爽天天玩人人妻| 香蕉久久夜色精品升级完成| 国产综合精品久久亚洲| 性色欲网站人妻丰满中文久久不卡 | 国产福利电影一区二区三区久久老子无码午夜伦不| 欧美亚洲另类久久综合| 日韩人妻无码一区二区三区久久| 999久久久免费国产精品播放| 亚洲精品乱码久久久久久自慰| 久久成人精品| 久久99精品久久久久久野外| 99久久99久久久精品齐齐| 成人久久免费网站| 久久精品极品盛宴观看| 亚洲国产成人精品久久久国产成人一区二区三区综 | 国产99精品久久| 久久亚洲私人国产精品| 国产精品久久久久久久人人看| 精品久久久久久久久久久久久久久| 国产一区二区三区久久| 久久久久国产精品| 亚洲国产精久久久久久久| 久久99亚洲网美利坚合众国| 久久天天躁狠狠躁夜夜96流白浆 | 久久中文字幕人妻丝袜| 一本大道久久香蕉成人网| 亚洲国产精品无码久久青草 | 久久人人爽人人爽人人片AV东京热| 国产精品99久久久久久猫咪| 久久99精品免费一区二区| yellow中文字幕久久网|