题目链接:http://poj.org/problem?id=3468

题意:给出一个数列,两种操作:(1)将区间[L,R]的数字统一加上某个值;(2)查询区间[L,R]的数字之和。

思路:数列A,那么区间[1,x]的和为:


struct BIT
{
    i64 a[N];

    void clear()
    {
        clr(a,0);
    }

    void add(int x,int t)
    {
        while(x<N) a[x]+=t,x+=x&-x;
    }

    i64 get(int x)
    {
        i64 ans=0;
        while(x) ans+=a[x],x-=x&-x;
        return ans;
    }
};

BIT a,b;

int n,m;
i64 p[N];

int main()
{
    Rush(n)
    {
        RD(m);
        int i;
        FOR1(i,n) RD(p[i]),p[i]+=p[i-1];
        a.clear(); b.clear();
        char op[10];
        int L,R,x;
        while(m--)
        {
            RD(op);
            if(op[0]=='Q')
            {
                RD(L,R);
                PR(p[R]-p[L-1]+(R+1)*a.get(R)-b.get(R)-L*a.get(L-1)+b.get(L-1));
            }
            else
            {
                RD(L,R,x);
                a.add(L,x);
                a.add(R+1,-x);
                b.add(L,x*L);
                b.add(R+1,-x*(R+1));
            }
        }
    }
}

  

POJ 3468 A Simple Problem with Integers(树状数组)的更多相关文章

  1. A Simple Problem with Integers(树状数组HDU4267)

    A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (J ...

  2. HDU 4267 A Simple Problem with Integers --树状数组

    题意:给一个序列,操作1:给区间[a,b]中(i-a)%k==0的位置 i 的值都加上val  操作2:查询 i 位置的值 解法:树状数组记录更新值. 由 (i-a)%k == 0 得知 i%k == ...

  3. POJ3468 A Simple Problem With Integers 树状数组 区间更新区间询问

    今天学了很多关于树状数组的技巧.一个是利用树状数组可以简单的实现段更新,点询问(二维的段更新点询问也可以),每次修改只需要修改2个角或者4个角就可以了,另外一个技巧就是这题,原本用线段树做,现在可以用 ...

  4. POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询)

    POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询) 题意分析 注意一下懒惰标记,数据部分和更新时的数字都要是long long ,别的没什么大 ...

  5. poj 3468 A Simple Problem with Integers 【线段树-成段更新】

    题目:id=3468" target="_blank">poj 3468 A Simple Problem with Integers 题意:给出n个数.两种操作 ...

  6. 线段树(成段更新) POJ 3468 A Simple Problem with Integers

    题目传送门 /* 线段树-成段更新:裸题,成段增减,区间求和 注意:开long long:) */ #include <cstdio> #include <iostream> ...

  7. poj 3468 A Simple Problem with Integers(线段树+区间更新+区间求和)

    题目链接:id=3468http://">http://poj.org/problem? id=3468 A Simple Problem with Integers Time Lim ...

  8. POJ 3468 A Simple Problem with Integers(线段树功能:区间加减区间求和)

    题目链接:http://poj.org/problem?id=3468 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit ...

  9. POJ 3468 A Simple Problem with Integers(分块入门)

    题目链接:http://poj.org/problem?id=3468 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit ...

  10. poj 3468 A Simple Problem with Integers 线段树区间加,区间查询和

    A Simple Problem with Integers Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?i ...

随机推荐

  1. linux创建线程之pthread_create

    说明:本文转自多线程编程之pthread_create函数应用,在此基础上笔者做了些许改动. pthread_create函数 函数简介 pthread_create是UNIX环境创建线程函数 头文件 ...

  2. hg211g破解获取管理员密码,可以连接路由器。默认光猫来拨号。

    先通过这种方式获取telecomadmin密码:1.使用useradmin用户登录设备2.在IE地址栏输入该路径”192.168.1.1/backupsettings.html”3.点击保存设备备份配 ...

  3. 【CocoaPods】配置CocoaPods前 - 本地安装好Ruby环境

    xcode (反正就是代码编辑器) Xcode就不用说了把. homebrew (反正就是软件管理器) homebrew是一个包管理器,用于在mac上安装一些os x上没有的UNiX工具(比如wget ...

  4. getHeight returns 0 for all Android UI objects

    It's 0 because in both onCreate and onStart, the view hasn't actually been drawn yet. You can get ar ...

  5. Eclipse配置默认的编码集为utf-8

    既然开了博,那就来点有用的. 可以使用下面的方法,让Eclipse对所有的项目里所有文件都按照指定的编码解析. Eclipse安装目录下有一个eclipse.ini文件, 用记事本打开即可,在最后一行 ...

  6. 移动端页面使用rem来做适配

    文/九彩拼盘(简书作者)原文链接:http://www.jianshu.com/p/eb05c775d3c6著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. rem介绍 rem(font ...

  7. 【BZOJ】【1324】王者之剑

    网络流/二分图最大点权独立集 Amber(胡伯涛)论文<最小割模型在信息学竞赛中的应用>中的例题…… 感觉这个好神啊,果然是一切皆为网络流……这转化太神奇了 /************** ...

  8. Codeforces Round #363 (Div. 2)->B. One Bomb

    B. One Bomb time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  9. synergy--共享你的键鼠

    synergy用来分享一套键鼠,作用于多台主机.可作用于linux.Windows和mac平台.工作方式是:将一台主机作为服务器端,然后服务器端将会分享自己的键鼠,另一台主机作为客户端连接服务端就可以 ...

  10. 配置sql server2012属性 ms-help://MS.SQLCC.v10/MS.SQLSVR.v10.zh-CHS/s10de_5techref/html/6df812ad-4d80-4503-8a23-47719ce85624.htm

    服务与服务器是两个不同的概念,服务器是提供服务的计算机,配置服务器主要是对内存.处理器.安全性等几个方面配置.由于SQL Server 2005服务器的设置参数比较多,这里选一些比较常用的介绍. 配置 ...