• <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年9月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789

            常用鏈接

            留言簿(24)

            隨筆分類(lèi)(332)

            隨筆檔案(182)

            FRIENDS

            搜索

            積分與排名

            最新隨筆

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

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

             

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

             

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

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

            代碼如下 :

            代碼
            /*
            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{ //線段樹(shù)結(jié)構(gòu)體
                    friend 
            struct optLine;
                    Line () { sum 
            = 0; left = right = NULL; };
                    
            int l,r,sum;
                    
            struct Line *left, *right;
            }L;
            typedef 
            struct optLine { //線段樹(shù)操作結(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 ){ //建樹(shù)
                 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 ){ //查詢(xún)
                
            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久久免费国产精精品| 久久久久久午夜精品| 精品久久久久中文字| 久久久WWW成人免费毛片| 久久综合亚洲色一区二区三区| 亚洲欧美成人综合久久久| 日韩一区二区久久久久久| 一本色道久久综合| 97精品久久天干天天天按摩 | 青草国产精品久久久久久| 亚洲午夜精品久久久久久人妖| 亚洲人成电影网站久久| 91久久精品91久久性色| 亚洲精品国产综合久久一线| 97久久超碰国产精品旧版| 偷窥少妇久久久久久久久| 韩国三级大全久久网站| 亚洲国产精品综合久久网络| 国产精品久久久久久福利69堂| 午夜精品久久久久久久无码| 久久er国产精品免费观看2| 97视频久久久| 久久久艹| www.久久精品| 97精品伊人久久久大香线蕉 | 久久精品不卡| 999久久久无码国产精品| AV无码久久久久不卡蜜桃| 久久久99精品一区二区| 久久免费视频网站| 人妻无码αv中文字幕久久| 香港aa三级久久三级老师2021国产三级精品三级在 | 99久久精品免费观看国产| 久久综合给合久久狠狠狠97色69| 国产A级毛片久久久精品毛片| 久久国产色AV免费观看| 久久国产AVJUST麻豆| 精品国产婷婷久久久| 99久久免费国产精精品| 久久99国产乱子伦精品免费| 中文字幕久久精品无码|