• <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ǎ崽 閱讀(669) 評論(0)  編輯 收藏 引用
            久久五月精品中文字幕| 99久久人妻无码精品系列蜜桃| 久久人人爽人人爽人人片AV不 | 久久久久亚洲精品天堂| 区亚洲欧美一级久久精品亚洲精品成人网久久久久| 久久久亚洲欧洲日产国码aⅴ| 久久综合给合久久狠狠狠97色| 色偷偷偷久久伊人大杳蕉| 浪潮AV色综合久久天堂| www久久久天天com| 国产精品成人99久久久久91gav| 99久久www免费人成精品| 久久夜色精品国产亚洲av| 久久综合伊人77777| 人妻无码αv中文字幕久久 | 麻豆亚洲AV永久无码精品久久| 影音先锋女人AV鲁色资源网久久| 久久SE精品一区二区| 国产成人久久AV免费| 久久精品国产色蜜蜜麻豆| 精品久久亚洲中文无码| 7国产欧美日韩综合天堂中文久久久久 | 精品乱码久久久久久久| 亚洲成色999久久网站| 性做久久久久久久久老女人| 久久久久久久女国产乱让韩| 色综合久久88色综合天天| 久久亚洲熟女cc98cm| 97超级碰碰碰碰久久久久 | 日韩精品久久无码中文字幕| 亚洲国产精品久久66| 99久久精品免费看国产一区二区三区 | 久久久九九有精品国产| 久久久久久久久66精品片| 伊人久久无码精品中文字幕| 国产精品久久久久AV福利动漫| 伊人久久一区二区三区无码| 久久成人18免费网站| 女人香蕉久久**毛片精品| 久久久无码一区二区三区| 久久婷婷五月综合成人D啪|