题目链接: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. Session设置不当导致API变成单线程问题的解决

    起因: 最近开发一个项目,有个接口很慢(数据库的问题),然后在执行期间,随手去点了其他功能(调用其他接口),发现不响应了.等那个很慢的接口返回结果了,这个功能才立马返回结果.  这明显是一个问题啊! ...

  2. mysql卸载

    先执行mysql安装程序,点击移除,然后再删除对应的安装路径,必要的时候还要删除注册表信息.

  3. 微软职位内部推荐-Senior Android Developer

    微软近期Open的职位: Position: Senior SDE-- Mobile Products Android/iOS/WP Senior Developer Contact Person: ...

  4. cxf简单实例

    CXF是一个基于 Servlet 技术的 SOA 应用开发框架,简单来说,就是WebService的轻量级实现. 1.下载开发包:http://cxf.apache.org/download.html ...

  5. MVC下用C#实现Excel导出

    Aspx页面脚本: function exportxls() { window.open("/Common/HomeExport?startdate=" + $("#hi ...

  6. CADisplayLink

    什么是CADisplayLink CADisplayLink是一个能让我们以和屏幕刷新率相同的频率将内容画到屏幕上的定时器.我们在应用中创建一个新的 CADisplayLink 对象,把它添加到一个r ...

  7. html+css学习笔记 4[定位]

    如何让图1中的div2移动到如图2上的位置: 思路:哪些css命令能够影响盒子显示的位置呢? relative相对定位/定位偏移量 position:relative;  相对定位         a ...

  8. spoj 375 Query on a tree(树链剖分,线段树)

      Query on a tree Time Limit: 851MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu Sub ...

  9. oracle 字符集

    ---- 在国内外大中型数据库管理系统中,把ORACLE作为数据库管理平台的用户比较多.ORACLE 不论是数据库管理能力还是安全性都是无可非议的,但是,它在汉字信息的显示方面着实给中国用户带来不少麻 ...

  10. properties配置应用,为什么需要使用properties文件

    在项目中我们常常会使用Constants常量类,达到系统全局配置的目的. 但是有些常量需要动态的配置,如果项目上线后,每次修改Constants.java然后再编译,再上传Constants.clas ...