• <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>
            隨筆-72  評論-126  文章-0  trackbacks-0
            http://acm.hdu.edu.cn/showproblem.php?pid=1166

            #include<stdio.h>
            #define MAX 50001
            #define lowbit(x) (x&(-x))
            int sum[MAX],tree[MAX];
            int query(int x)
            {
                
            int sum = 0;
                
            while(x>0)
                {
                    sum 
            += tree[x];
                    x 
            -= lowbit(x);
                }
                
            return sum;
            }
            void add(int a,int b,int n)
            {
                
            while(a<=n)
                {
                    tree[a] 
            += b;
                    a 
            += lowbit(a);
                }
            }
            int main()
            {
                
            int T,n,i,cas,data;
                scanf(
            "%d",&T);
                
            for(cas=1;cas<=T;cas++)
                {
                    scanf(
            "%d",&n);
                    tree[
            0= sum[0= 0;
                    
            for(i=1;i<=n;i++)
                    {
                        scanf(
            "%d",&data);
                        sum[i] 
            = sum[i-1+ data;
                        tree[i] 
            = sum[i] - sum[i - lowbit(i)];
                    }
                    
            char com[10];
                    
            int a,b;
                    printf(
            "Case %d:\n",cas);
                    
            while(scanf("%s",com),com[0]-'E')
                    {
                        scanf(
            "%d%d",&a,&b);
                        
            if(com[0]=='Q')
                            printf(
            "%d\n",query(b) - query(a-1));
                        
            else if(com[0]=='A')
                            add(a,b,n);
                        
            else
                            add(a,
            -b,n);
                    }
                }
                
            return 0;
            }


            二維的話就這樣抄作

            int query(int x,int y)
            {
                
            int sum=0;
                
            while(x>0)
                {
                    
            int tmp = y;
                    
            while(tmp>0)
                    {
                        sum 
            += tree[x][tmp];
                        tmp 
            -= lowbit(tmp);
                    }
                    x 
            -= lowbit(x);
                }
                
            return sum;
            }
            void add(int x,int y,int num)
            {
                
            while(x<=MAX)
                {
                    
            int tmp = y;
                    
            while(tmp<=MAX)
                    {
                        tree[x][tmp] 
            += num;
                        tmp 
            += lowbit(tmp);
                    }
                    x 
            += lowbit(x);
                }
            }


            兩道赤裸裸的二維樹形數組
            http://acm.hdu.edu.cn/showproblem.php?pid=1892
            http://acm.hdu.edu.cn/showproblem.php?pid=2642

            稍微變化一點
            http://acm.hdu.edu.cn/showproblem.php?pid=1541
            http://acm.hdu.edu.cn/showproblem.php?pid=2227
            http://acm.hdu.edu.cn/showproblem.php?pid=2688
            posted on 2009-03-19 17:44 shǎ崽 閱讀(667) 評論(0)  編輯 收藏 引用
            久久精品亚洲精品国产欧美| 99久久做夜夜爱天天做精品| 亚洲精品乱码久久久久久不卡| 日本免费久久久久久久网站| 久久久中文字幕日本| 国产精品99久久不卡| 久久综合综合久久97色| 色综合久久综合网观看| 久久不射电影网| 久久精品国产亚洲麻豆| 久久中文字幕一区二区| 国产精品免费久久久久影院| 久久久久亚洲AV成人网| 四虎亚洲国产成人久久精品| 日本精品久久久久影院日本| 欧美精品九九99久久在观看| 久久久无码精品亚洲日韩京东传媒 | 九九精品99久久久香蕉| 国产毛片欧美毛片久久久| 亚洲精品高清国产一线久久| 久久久久久人妻无码| 国产欧美一区二区久久| 四虎影视久久久免费观看| 中文字幕无码免费久久| 国产成人久久激情91| 国内精品久久国产大陆| 国产一区二区精品久久岳 | 国产亚洲精品久久久久秋霞| 久久夜色精品国产| 久久久久国产精品人妻| 国产精品99精品久久免费| 久久国产香蕉视频| 亚洲国产精品无码久久久不卡| 精品久久久久久无码中文野结衣 | 亚洲精品高清国产一久久| 色综合久久综合网观看| 久久久久99这里有精品10| 久久久久亚洲av无码专区| 国产精品无码久久四虎| 亚洲精品美女久久777777| 91精品免费久久久久久久久|