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

            gzwzm06

              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
              1 隨筆 :: 52 文章 :: 17 評論 :: 0 Trackbacks
              1#include <cstdio>
              2#include <algorithm>
              3using namespace std;
              4
              5const int SIZE = 100001;
              6
              7struct RANGE
              8{
              9    int m_S, m_E;
             10    int m_p;
             11
             12    //按區間右端從大到小排序,再按左端從小到大排
             13    //將左端依序插入線段樹,即將區間將大先放入,就能得出包含關系
             14    bool operator < (const RANGE& other)
             15    {
             16        if ( m_E != other.m_E )
             17            return (m_E > other.m_E);
             18        
             19        return (m_S < other.m_S);
             20    }

             21}
            cow[SIZE];
             22
             23//線段樹
             24struct STREE
             25{
             26    int m_leftPos, m_rightPos;
             27    int m_left, m_right;
             28    int m_ItNum;                //記錄區間的左端個數
             29}
            tree[SIZE * 2];
             30
             31int N, result[SIZE];
             32
             33void BuildSTree(int& index, const int& l, const int& r)
             34{
             35    int id = index;
             36    tree[id].m_left = l, tree[id].m_right = r;
             37    tree[id].m_ItNum = 0;
             38    if ( l == r )
             39    {
             40        tree[id].m_leftPos = tree[id].m_rightPos = -1;
             41        return ;
             42    }

             43
             44    int mid = (l + r) >> 1;
             45
             46    tree[id].m_leftPos = ++index;
             47    BuildSTree( index, l, mid );
             48    tree[id].m_rightPos = ++index;
             49    BuildSTree( index, mid + 1, r );
             50}

             51
             52int Insert(const int& id, const int& s)
             53{
             54    int num = 0;
             55    if ( tree[id].m_left == s && tree[id].m_right == s )
             56    {
             57        tree[id].m_ItNum++;
             58        return (tree[id].m_ItNum - 1);
             59    }

             60
             61    int mid = (tree[id].m_left + tree[id].m_right) >> 1;
             62
             63    if ( s <= mid ) {
             64        tree[id].m_ItNum++;
             65        num += Insert(tree[id].m_leftPos, s);
             66    }

             67    else {
             68        num = tree[id].m_ItNum;
             69        num += Insert(tree[id].m_rightPos, s);
             70    }

             71
             72    return num;
             73}

             74
             75int main()
             76{
             77    freopen("1.txt""r", stdin);
             78    int i, t, maxN;
             79
             80    while ( true )
             81    {
             82        scanf("%d"&N);
             83        if ( N == 0 )
             84            break;
             85        
             86        maxN = 0;
             87        for ( i = 0; i < N; ++i )
             88        {
             89            scanf("%d %d"&cow[i].m_S, &cow[i].m_E);
             90            cow[i].m_p = i;
             91            if ( cow[i].m_E > maxN )
             92                maxN = cow[i].m_E;
             93        }

             94        t = 0;
             95        BuildSTree(t, 0, maxN);
             96        sort(cow, cow + N);
             97
             98        result[cow[0].m_p] = Insert(0, cow[0].m_S);
             99        for ( i = 1; i < N; ++i )
            100        {
            101            result[cow[i].m_p] = Insert(0, cow[i].m_S);
            102            //處理區間相等的情況,插入操作還是照做,結果就為等價
            103            if ( cow[i].m_E == cow[i - 1].m_E && cow[i].m_S == cow[i - 1].m_S )
            104                result[cow[i].m_p] = result[cow[i - 1].m_p];
            105        }

            106
            107        for ( i = 0; i < N - 1++i )
            108        {
            109            printf("%d ", result[i]);
            110        }

            111        printf("%d\n", result[i]);
            112    }

            113    return 0;
            114}
            posted on 2009-04-11 16:15 閱讀(232) 評論(0)  編輯 收藏 引用 所屬分類: 數據結構
            99久久精品国产一区二区蜜芽| 国内精品久久久久国产盗摄| 97视频久久久| 无码人妻久久一区二区三区| 91精品国产9l久久久久| 久久免费视频网站| 亚洲综合久久夜AV | 色8久久人人97超碰香蕉987| 久久久久国产精品| 国产成人久久精品区一区二区| 国内精品免费久久影院| 欧美亚洲国产精品久久久久| 久久偷看各类wc女厕嘘嘘| 91久久香蕉国产熟女线看| 午夜精品久久久久久久无码| 久久99国产综合精品女同| 久久婷婷五月综合成人D啪| 青青草原精品99久久精品66| 久久精品国产亚洲Aⅴ香蕉| 天堂久久天堂AV色综合| 久久久久国产一区二区| 精品久久人妻av中文字幕| 亚洲精品WWW久久久久久| 久久精品草草草| 久久久女人与动物群交毛片| 热久久国产欧美一区二区精品 | 久久影视综合亚洲| 精品无码久久久久国产| 久久久久亚洲AV无码观看| 国产国产成人久久精品| 99国产精品久久久久久久成人热| 久久人人青草97香蕉| 久久精品国产一区二区电影| 欧美精品一区二区精品久久 | 久久久久久亚洲精品成人| 尹人香蕉久久99天天拍| 久久无码人妻精品一区二区三区| 国产成人久久AV免费| 久久久噜噜噜久久中文福利| 性欧美大战久久久久久久久| 久久久久国产精品人妻|