• <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>
            心如止水
            Je n'ai pas le temps
            posts - 400,comments - 130,trackbacks - 0
            線段樹,區(qū)間增減,區(qū)間求和。
            以下是我的代碼:
            /*
             * Author:  lee1r
             * Created Time:  2011/8/2 10:51:34
             * File Name: poj3468.cpp
             
            */
            #include
            <iostream>
            #include
            <sstream>
            #include
            <fstream>
            #include
            <vector>
            #include
            <list>
            #include
            <deque>
            #include
            <queue>
            #include
            <stack>
            #include
            <map>
            #include
            <set>
            #include
            <bitset>
            #include
            <algorithm>
            #include
            <cstdio>
            #include
            <cstdlib>
            #include
            <cstring>
            #include
            <cctype>
            #include
            <cmath>
            #include
            <ctime>
            #define L(x) ((x)<<1)
            #define R(x) (((x)<<1)+1)
            #define Half(x) ((x)>>1)
            #define lowbit(x) ((x)&(-(x)))
            using namespace std;
            typedef 
            long long int64;
            typedef unsigned 
            long long uint64;
            const int kMaxn(100007);

            struct Node
            {
                
            int a,b;
                int64 sum,add;
            };

            int n,Q,r[kMaxn];
            Node tree[kMaxn
            <<2];

            void Build(int node,int x,int y)
            {
                tree[node].a
            =x;
                tree[node].b
            =y;
                tree[node].add
            =0;
                
            if(x==y)
                    tree[node].sum
            =r[x];
                
            else
                {
                    
            int m(Half(x+y));
                    Build(L(node),x,m);
                    Build(R(node),m
            +1,y);
                    tree[node].sum
            =tree[L(node)].sum+tree[R(node)].sum;
                }
            }

            void Update(int node)
            {
                
            if(tree[node].add)
                {
                    tree[L(node)].add
            +=tree[node].add;
                    tree[R(node)].add
            +=tree[node].add;
                    tree[L(node)].sum
            +=(tree[L(node)].b-tree[L(node)].a+1)*tree[node].add;
                    tree[R(node)].sum
            +=(tree[R(node)].b-tree[R(node)].a+1)*tree[node].add;
                    tree[node].add
            =0;
                }
            }

            void Add(int node,int x,int y,int delta)
            {
                
            if(x<=tree[node].a && tree[node].b<=y)
                {
                    tree[node].add
            +=delta;
                    tree[node].sum
            +=(tree[node].b-tree[node].a+1)*delta;
                }
                
            else
                {
                    Update(node);
                    
            int m(Half(tree[node].a+tree[node].b));
                    
            if(x<=m)
                        Add(L(node),x,y,delta);
                    
            if(y>m)
                        Add(R(node),x,y,delta);
                    tree[node].sum
            =tree[L(node)].sum+tree[R(node)].sum;
                }
            }

            int64 Sum(
            int node,int x,int y)
            {
                
            if(x<=tree[node].a && tree[node].b<=y)
                    
            return tree[node].sum;
                
            else
                {
                    Update(node);
                    int64 re(
            0);
                    
            int m(Half(tree[node].a+tree[node].b));
                    
            if(x<=m)
                        re
            +=Sum(L(node),x,y);
                    
            if(y>m)
                        re
            +=Sum(R(node),x,y);
                    
            return re;
                }
            }

            int main() 
            {
                
            //freopen("data.in","r",stdin);
                
                
            while(scanf("%d%d",&n,&Q)==2)
                {
                    
            for(int i=1;i<=n;i++)
                        scanf(
            "%d",&r[i]);
                    
                    Build(
            1,1,n);
                    
                    
            while(Q--)
                    {
                        
            string cmd;
                        
            int a,b,c;
                        cin
            >>cmd;
                        
            if(cmd=="C")
                        {
                            scanf(
            "%d%d%d",&a,&b,&c);
                            Add(
            1,a,b,c);
                        }
                        
            else
                        {
                            scanf(
            "%d%d",&a,&b);
                            cout
            <<Sum(1,a,b)<<endl;
                        }
                    }
                }
                
                
            return 0;
            }
            posted on 2011-08-02 11:15 lee1r 閱讀(463) 評論(0)  編輯 收藏 引用 所屬分類: 題目分類:數據結構
            狠狠干狠狠久久| 久久久久久噜噜精品免费直播| 伊人久久大香线蕉无码麻豆| 精品国产乱码久久久久久呢| 99精品国产在热久久无毒不卡 | 日本欧美国产精品第一页久久| 久久亚洲国产精品五月天婷| 精品免费久久久久久久| 精品久久久久久无码中文野结衣| 国产免费久久精品99re丫y| 久久精品一区二区| 国产A级毛片久久久精品毛片| 久久99毛片免费观看不卡| 久久久久亚洲av综合波多野结衣| 88久久精品无码一区二区毛片 | 国产精品免费久久久久电影网| 伊人久久大香线蕉成人| 国内精品伊人久久久久影院对白| 亚洲精品午夜国产VA久久成人| 久久人人爽人爽人人爽av| 国产精品一区二区久久 | 日韩精品久久久久久免费| 亚洲&#228;v永久无码精品天堂久久| 久久这里只有精品18| 久久国产色av免费看| 日本国产精品久久| 国产成人无码精品久久久久免费| 国产精品18久久久久久vr| 久久99精品久久久久婷婷| 亚洲精品乱码久久久久久| 综合网日日天干夜夜久久 | 国产精品激情综合久久| 91精品国产9l久久久久| jizzjizz国产精品久久| 国产69精品久久久久777| 精品久久久无码人妻中文字幕豆芽 | 99久久精品免费国产大片| 国产精品免费久久| 久久久WWW成人免费毛片| 日韩中文久久| 久久丫忘忧草产品|