• <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 閱讀(459) 評論(0)  編輯 收藏 引用 所屬分類: 題目分類:數(shù)據(jù)結(jié)構(gòu)
            欧美一级久久久久久久大片| 久久九九精品99国产精品| 亚洲国产日韩欧美久久| 久久伊人中文无码| 一本色综合网久久| 久久精品国产精品青草app| 精品欧美一区二区三区久久久| 欧美久久天天综合香蕉伊| 少妇人妻综合久久中文字幕| 国产精品成人无码久久久久久| 午夜精品久久久久久中宇| 久久亚洲中文字幕精品一区| 亚洲va中文字幕无码久久不卡| 亚洲国产精品一区二区久久| 精品无码久久久久久尤物| 亚洲精品无码久久一线| 精品久久国产一区二区三区香蕉| 亚洲精品无码久久千人斩| 久久亚洲AV永久无码精品| 97久久精品国产精品青草| 久久国产亚洲精品无码| 久久亚洲精品国产精品婷婷| 狠狠色伊人久久精品综合网 | 久久这里只有精品视频99| 99精品久久久久久久婷婷| 久久国产高清一区二区三区| 国产精品久久久久影视不卡| 99久久国产精品免费一区二区| 日韩人妻无码一区二区三区久久99| 精品99久久aaa一级毛片| 99久久综合狠狠综合久久| 久久本道伊人久久| 秋霞久久国产精品电影院| 91精品国产91久久久久久| 日本免费久久久久久久网站| 99久久精品国产高清一区二区| 日日噜噜夜夜狠狠久久丁香五月| 99久久免费国产精精品| 激情伊人五月天久久综合| WWW婷婷AV久久久影片| 久久精品国产精品青草app|