• <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ǎ崽 閱讀(676) 評論(0)  編輯 收藏 引用
            国产成人精品久久| 久久综合伊人77777| a级成人毛片久久| 青青青国产成人久久111网站| 久久午夜综合久久| 久久精品国产99国产精品澳门| 亚洲精品美女久久久久99小说| 精品国际久久久久999波多野| 麻豆国内精品久久久久久| 久久久久一区二区三区| 国产色综合久久无码有码| 色综合久久中文字幕综合网| 91精品国产综合久久四虎久久无码一级| 亚洲国产成人久久一区久久| 国产精品热久久无码av| 久久久久久毛片免费看| 亚洲精品tv久久久久| 国产精品久久久香蕉| 91麻豆国产精品91久久久| 亚洲国产成人精品91久久久| 久久精品久久久久观看99水蜜桃| 模特私拍国产精品久久| 亚洲狠狠婷婷综合久久蜜芽| 国产毛片欧美毛片久久久| 久久不射电影网| 国产精品毛片久久久久久久| 国产亚洲成人久久| 久久香蕉国产线看观看99| 18岁日韩内射颜射午夜久久成人| 久久综合久久久| 色婷婷综合久久久久中文一区二区 | 久久一区二区免费播放| 色婷婷综合久久久久中文一区二区| 精品久久久久中文字| 国产精品成人久久久久久久| 欧美777精品久久久久网| 久久国产乱子伦精品免费强| 久久久久亚洲精品天堂| 人妻精品久久无码区| 777久久精品一区二区三区无码| 国产91色综合久久免费分享|