• <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>

            coreBugZJ

            此 blog 已棄。

            reverse order 1,HUST Monthly 2011.04.09 之 C,1433

            reverse order 1

            Time Limit: 1 Sec Memory Limit: 128 MB
            Submissions: 531 Solved: 87

            Description

            Here is a sequence a1..n, which is a disordered sequence from 1 to N. If i < j and ai > aj, then <i, j> is called a pair of inversion. And b1..n-1 is defined as follows, bk is the number of the total inversion pairs in array a, when i<=k<j. Now the array b is required while the array a is known.

             

            Input

            Several cases end with the end of the file;

            And each of the cases includes two lines, a integer n(2<=n<=10^5)in the first line, and the second line followed with n integer, which is in the presentation of array a;

             

            Output

            Output the answer of each case in a line, namely the array b, and a space is required between the adjacent integers.

             

            Sample Input

            5
            3 1 4 2 5

            Sample Output

            2 1 2 0
             
            樹狀數(shù)組。。。
             1#include <iostream>
             2
             3using namespace std;
             4
             5typedef  long long  Lint;
             6
             7const int L = 200009;
             8
             9int n, a[ L ];
            10Lint b[ L ], al[ L ], sl[ L ], ar[ L ], sr[ L ];
            11
            12void init( Lint a[], Lint s[] ) {
            13        int i;
            14        for ( i = 0; i <= n; ++i ) {
            15                a[ i ] = s[ i ] = 0;
            16        }

            17}

            18
            19#define  getBit(i)  (i&(i^(i-1)))
            20
            21void add( Lint a[], Lint s[], int i, Lint d ) {
            22        a[ i ] += d;
            23        while ( i <= n ) {
            24                s[ i ] += d;
            25                i += getBit(i);
            26        }

            27}

            28
            29Lint get( Lint a[], Lint s[], int i ) {
            30        Lint res = -a[ i ];
            31        while ( i > 0 ) {
            32                res += s[ i ];
            33                i -= getBit( i );
            34        }

            35        return res;
            36}

            37
            38int main() {
            39        int i;
            40        while ( cin >> n ) {
            41                for ( i = 1; i <= n; ++i ) {
            42                        cin >> a[ i ];
            43                }

            44                init( al, sl );
            45                init( ar, sr );
            46                for ( i = n; i > 0--i ) {
            47                        add( ar, sr, a[ i ], 1 );
            48                }

            49                b[ 1 ] = get( ar, sr, a[ 1 ] );
            50                add( al, sl, n+1-a[1], 1 );
            51                for ( i = 2; i < n; ++i ) {
            52                        add( ar, sr, a[i-1], -1 );
            53                        add( al, sl, n+1-a[i], 1 );
            54                        b[ i ] = b[ i - 1 ] - get( al, sl, n+1-a[i] ) + get( ar, sr, a[i] );
            55                }

            56                cout << b[ 1 ];
            57                for ( i = 2; i < n; ++i ) {
            58                        cout << " " << b[ i ];
            59                }

            60                cout << "\n";
            61        }

            62        return 0;
            63}

            64

            posted on 2011-04-09 18:35 coreBugZJ 閱讀(926) 評論(0)  編輯 收藏 引用 所屬分類: ACM

            色欲久久久天天天综合网| 精品无码久久久久久久久久| 亚洲欧美国产日韩综合久久| 2021国产精品久久精品| 久久丫精品国产亚洲av不卡| 久久最近最新中文字幕大全 | 亚洲国产精品嫩草影院久久| 久久人与动人物a级毛片| 狠狠色婷婷综合天天久久丁香| 久久久精品日本一区二区三区| 蜜臀av性久久久久蜜臀aⅴ| 国内精品久久久久久久久电影网 | 尹人香蕉久久99天天拍| 久久本道伊人久久| 久久久久亚洲AV成人网人人网站| 青青草国产成人久久91网| 无码人妻久久一区二区三区| 久久精品国产亚洲7777| 久久精品亚洲精品国产色婷| 欧美午夜精品久久久久久浪潮| 久久久91精品国产一区二区三区| 亚洲综合精品香蕉久久网| 久久精品国产一区二区三区| 99国产精品久久| 狠狠色婷婷久久一区二区三区| 亚洲AⅤ优女AV综合久久久| 久久99亚洲综合精品首页| 97久久久久人妻精品专区| 无码精品久久久久久人妻中字| 久久人人爽人人爽人人片av麻烦| 久久精品国产精品亚洲| 亚洲精品国产成人99久久| 国产亚洲精品自在久久| 久久久久人妻一区精品色 | 中文无码久久精品| 久久精品亚洲精品国产欧美| 国产精品岛国久久久久| 久久精品成人欧美大片| 久久久精品视频免费观看| 久久久久黑人强伦姧人妻| 蜜桃麻豆www久久国产精品|