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

            ACM___________________________

            ______________白白の屋
            posts - 182, comments - 102, trackbacks - 0, articles - 0
            <2010年8月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            常用鏈接

            留言簿(24)

            隨筆分類(332)

            隨筆檔案(182)

            FRIENDS

            搜索

            積分與排名

            最新隨筆

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            MiYu原創(chuàng), 轉(zhuǎn)帖請(qǐng)注明 : 轉(zhuǎn)載自 ______________白白の屋    

             

            先前做了這一題, 不過(guò)是用 樹狀數(shù)組做的, 對(duì)于這一類型的題目也來(lái)說(shuō)非常方便快捷. 具體地址 : http://www.cnblogs.com/MiYu/archive/2010/08/25/1808441.html

             

            這幾天學(xué)了 線段樹 , 不是很明白它的用途 和 使用方法,  因?yàn)?聽說(shuō) 樹狀數(shù)組是 線段樹的 一種特殊情況 ( 部分資料是這么說(shuō)的 ) .  于是就又做了一次這個(gè)題目.

            不過(guò)使用的是線段樹的 方法 :

            代碼如下 :

            代碼
            /*
            MiYu原創(chuàng), 轉(zhuǎn)帖請(qǐng)注明 : 轉(zhuǎn)載自 ______________白白の屋
                      
            http://www.cnblog.com/MiYu
            Author By : MiYu
            Test      : 3
            Program   : 1166
            */

            #include 
            <iostream>
            #include 
            <algorithm>
            using namespace std;
            typedef 
            struct Line{ //線段樹結(jié)構(gòu)體
                    friend 
            struct optLine;
                    Line () { sum 
            = 0; left = right = NULL; };
                    
            int l,r,sum;
                    
            struct Line *left, *right;
            }L;
            typedef 
            struct optLine { //線段樹操作結(jié)構(gòu)
                   
            void Creat ( struct Line *node, int beg, int end );
                   
            void modify ( struct Line *node, int pos,int val );
                   
            int quy ( struct Line *node, int beg, int end );     
            }OPT;
            void optLine::Creat ( struct Line *node, int beg, int end ){ //建樹
                 node
            ->= beg;  node->= end;
                 
            if ( beg == end ) return;
                 
            int mid = ( node->+ node->r ) >> 1;
                 L 
            *= new L;  L *= new L;
                 node
            ->left = p; node->right = q;
                 Creat ( p, beg, mid );   Creat ( q, mid 
            + 1, end );          
            }
            void optLine::modify ( struct Line *node, int pos, int val ){ //修改
                 
            if ( pos >= node->&& pos <= node->r ) node->sum += val;
                 
            if ( node->== node->r ) return;
                 
            int mid = ( node->+ node->r ) >> 1;
                 
            if ( mid >= pos ) modify ( node->left, pos, val );
                 
            else if ( mid < pos ) modify ( node->right, pos,val );
            }
            int optLine::quy ( struct Line *node, int beg, int end ){ //查詢
                
            int sum = 0;  int mid = ( node->+ node->r ) >> 1;
                
            if ( node->== beg && node->== end ) return node->sum;
                
            if ( mid >= end ) return sum += quy ( node->left, beg,end );
                
            else if ( beg > mid ) return sum += quy ( node->right, beg, end ); 
                
            else {
                      
            return sum += quy ( node->left, beg, mid ) + quy ( node->right, mid+1,end );     
                }   
            }
            inline 
            bool scan_ud(int &num) 
            {
                    
            char in;
                    
            in=getchar();
                    
            if(in==EOF) return false;
                    
            while(in<'0'||in>'9'in=getchar();
                    num
            =in-'0';
                    
            while(in=getchar(),in>='0'&&in<='9'){
                            num
            *=10,num+=in-'0';
                    }
                    
            return true;
            }
            int main ( int T, int N )
            {
                scan_ud ( T );
                
            for ( int ca = 1; ca <= T ; ++ ca ){
                     printf ( 
            "Case %d:\n",ca );
                     scan_ud ( N );    OPT opt;  L 
            *root = new L;   int val,x,y;
                     opt.Creat ( root, 
            1, N );  
                     
            for ( int i = 1; i <= N; ++ i ){
                          scan_ud ( val );  opt.modify ( root, i, val );    
                     }
                     
            char ask[10];  
                     
            while ( scanf ( "%s", ask ), ask[0!= 'E' ){
                            scanf ( 
            "%d%d",&x,&y );
                            
            switch ( ask[0] ){
                                    
            case 'Q':  printf ( "%d\n",opt.quy ( root, x,y ) ); break;
                                    
            case 'A':  opt.modify ( root, x, y ); break;
                                    
            case 'S':  opt.modify ( root, x, -y ); break;      
                            }      
                     }
                }
                
            return 0;
            }

             

             

            久久婷婷五月综合色99啪ak| 色成年激情久久综合| 亚洲人成网站999久久久综合| 国产激情久久久久影院老熟女免费| 亚洲级αV无码毛片久久精品 | 亚洲AⅤ优女AV综合久久久| 欧美日韩成人精品久久久免费看| 伊人久久一区二区三区无码| 区久久AAA片69亚洲| 91精品观看91久久久久久| 日日狠狠久久偷偷色综合96蜜桃 | 青青青青久久精品国产h| 91久久精品视频| 国产精品美女久久久久网| 亚洲国产成人精品91久久久| 久久综合久久综合久久| 婷婷五月深深久久精品| 久久se精品一区二区影院| 无码人妻久久一区二区三区免费 | 97久久超碰国产精品2021| 99久久精品免费看国产一区二区三区 | 99久久亚洲综合精品网站| 久久精品国产亚洲av麻豆蜜芽 | 久久综合国产乱子伦精品免费| 午夜精品久久久久成人| 国产一区二区三精品久久久无广告| 日产精品久久久久久久| 久久99久国产麻精品66| 国产偷久久久精品专区| 国产日韩久久免费影院| 久久久九九有精品国产| 97久久精品人人做人人爽| 亚洲欧美日韩精品久久| 久久久久国色AV免费观看 | 久久亚洲精品人成综合网| 国产精品一久久香蕉国产线看| 日本三级久久网| 伊人久久无码中文字幕| 国产免费福利体检区久久| 麻豆久久久9性大片| 亚洲精品高清国产一久久|