• <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)  編輯 收藏 引用
            国产精品久久久久jk制服| 久久天天躁狠狠躁夜夜2020老熟妇| 久久久网中文字幕| 国产亚洲精品久久久久秋霞| 精品久久亚洲中文无码| 久久精品九九亚洲精品天堂 | 奇米影视7777久久精品人人爽| 香蕉aa三级久久毛片| 久久婷婷五月综合色高清 | 精品伊人久久大线蕉色首页| 久久综合给久久狠狠97色 | 国产成人久久精品麻豆一区| 亚洲&#228;v永久无码精品天堂久久 | 久久精品国产亚洲AV不卡| 97精品伊人久久大香线蕉| 青青青青久久精品国产| 亚洲成色www久久网站夜月| 国产精品免费看久久久香蕉| 麻豆一区二区99久久久久| 亚洲精品久久久www| 国产激情久久久久影院老熟女| 亚洲av成人无码久久精品| 无码任你躁久久久久久久| 国产免费久久精品99久久| 久久国产精品久久久| 久久国产精品77777| 国产激情久久久久久熟女老人| 无码精品久久一区二区三区| 99久久精品免费看国产免费| 国产成人综合久久综合| 亚洲国产另类久久久精品小说| 亚洲综合久久久| 亚洲欧美另类日本久久国产真实乱对白| 久久精品国产精品青草app| 99久久精品毛片免费播放| 久久精品人人做人人爽电影蜜月| 亚洲乱码精品久久久久..| 99久久香蕉国产线看观香| 一级a性色生活片久久无少妇一级婬片免费放 | 国内精品伊人久久久久777| 久久久久亚洲精品无码网址|