• <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年10月>
            262728293012
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            常用鏈接

            留言簿(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)?聽(tīng)說(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;
            }

             

             

            久久精品成人免费国产片小草| 亚洲精品乱码久久久久久蜜桃 | 91精品国产9l久久久久| 国产精品99久久久精品无码| 久久国产乱子伦精品免费午夜| 亚洲中文精品久久久久久不卡| 精品久久久一二三区| 无码乱码观看精品久久| 青春久久| 国内精品久久久久久久久电影网 | 97视频久久久| 久久人妻AV中文字幕| 久久久www免费人成精品| 久久久久久久综合狠狠综合| 国产精品久久久久久久久久影院 | 亚洲国产精品一区二区三区久久| 国产精品一区二区久久精品无码| 丁香五月综合久久激情| 国产亚洲成人久久| 欧美日韩成人精品久久久免费看| 四虎亚洲国产成人久久精品| 一个色综合久久| 久久精品人人做人人爽电影蜜月 | 日韩美女18网站久久精品 | 亚洲AV日韩AV天堂久久| 俺来也俺去啦久久综合网| 99久久成人18免费网站| 免费一级欧美大片久久网 | 狠狠久久综合伊人不卡| 亚洲精品午夜国产va久久| 久久久久亚洲AV无码网站| 99久久精品免费看国产一区二区三区| 久久精品亚洲乱码伦伦中文| 国内精品综合久久久40p| 久久精品国产福利国产秒| 一本大道久久香蕉成人网| 精品熟女少妇a∨免费久久| 狠狠色伊人久久精品综合网 | 日韩AV无码久久一区二区| 99久久国产热无码精品免费久久久久| 欧美精品一区二区久久|