• <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)  編輯 收藏 引用
            欧美日韩中文字幕久久伊人| 久久亚洲中文字幕精品有坂深雪 | 精品综合久久久久久98| 久久99这里只有精品国产| 精品久久久噜噜噜久久久| 久久se这里只有精品| 日日噜噜夜夜狠狠久久丁香五月| 九九久久99综合一区二区| 久久天天躁狠狠躁夜夜躁2014| 国产精品久久久久久久| 综合久久一区二区三区| 2021国产成人精品久久| 久久婷婷成人综合色综合| 欧美性大战久久久久久| 品成人欧美大片久久国产欧美| 久久人妻无码中文字幕| 亚洲精品久久久www| 国产精品99久久久久久董美香| 久久综合亚洲欧美成人| 久久综合视频网| 日韩一区二区三区视频久久| 亚洲国产天堂久久综合网站 | 亚洲欧美日韩中文久久| 久久精品无码一区二区三区免费| 国产精品久久久久AV福利动漫| 伊人伊成久久人综合网777| 久久婷婷人人澡人人| 国产高清国内精品福利99久久| 久久91精品久久91综合| 中文字幕亚洲综合久久| 91精品久久久久久无码| 亚洲狠狠久久综合一区77777 | 色播久久人人爽人人爽人人片AV| 久久国产成人午夜aⅴ影院| 国产亚洲精午夜久久久久久 | 久久亚洲国产精品成人AV秋霞| 久久人妻少妇嫩草AV蜜桃| 色婷婷综合久久久久中文字幕| 一级女性全黄久久生活片免费| 一本色道久久综合| 久久亚洲精精品中文字幕|