A Simple Problem with Integers
Time Limit: 5000MS   Memory Limit: 131072K
Total Submissions: 69589   Accepted: 21437
Case Time Limit: 2000MS

Description

You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of numbers in a given interval.

Input

The first line contains two numbers N and Q. 1 ≤ N,Q ≤ 100000.
The second line contains N numbers, the initial values of A1, A2, ... , AN. -1000000000 ≤ Ai ≤ 1000000000.
Each of the next Q lines represents an operation.
"C a b c" means adding c to each of Aa, Aa+1, ... , Ab. -10000 ≤ c ≤ 10000.
"Q a b" means querying the sum of Aa, Aa+1, ... , Ab.

Output

You need to answer all Q commands in order. One answer in a line.

Sample Input

10 5
1 2 3 4 5 6 7 8 9 10
Q 4 4
Q 1 10
Q 2 4
C 3 6 3
Q 2 4

Sample Output

4
55
9
15

Hint

The sums may exceed the range of 32-bit integers.

Source

 
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long LL;
const int INF=0x4fffffff;
const int EXP=1e-;
const int MS=; LL sum[MS];
LL C[][MS];
int N,Q; int lowbit(int x)
{
return x&(-x);
} void updata(int no,int x,LL value)
{
while(x<=N)
{
C[no][x]+=value;
x+=lowbit(x);
}
} LL getsum(int no,int x)
{
LL res=;
while(x>)
{
res+=C[no][x];
x-=lowbit(x);
}
return res;
} void solve()
{
scanf("%d%d",&N,&Q);
sum[]=;
for(int i=;i<=N;i++)
{
scanf("%lld",&sum[i]);
sum[i]+=sum[i-];
}
memset(C,,sizeof(C));
int l,r;
LL c;
char cmd[];
for(int i=;i<=Q;i++)
{
scanf("%s",cmd);
if(cmd[]=='Q')
{
scanf("%d%d",&l,&r);
LL ans=sum[r]-sum[l-]+(getsum(,r)-getsum(,r)*(N-r))-(getsum(,l-)-getsum(,l-)*(N-l+));
printf("%lld\n",ans);
}
else
{
scanf("%d%d%lld",&l,&r,&c);
updata(,l,c*(N-l+));
updata(,r+,(N-r)*(-c)); updata(,l,c);
updata(,r+,-c);
}
}
} int main()
{
solve();
return ;
}

A Simple Problem with Integers poj 3468 多树状数组解决区间修改问题。的更多相关文章

  1. C - A Simple Problem with Integers POJ - 3468 线段树模版(区间查询区间修改)

    参考qsc大佬的视频 太强惹 先膜一下 视频在b站 直接搜线段树即可 #include<cstdio> using namespace std; ; int n,a[maxn]; stru ...

  2. A Simple Problem with Integers(100棵树状数组)

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

  3. HDU 4267 A Simple Problem with Integers 多个树状数组

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

  4. A Simple Problem with Integers POJ - 3468 (线段树)

    思路:线段树,区间更新,区间查找 #include<iostream> #include<vector> #include<string> #include< ...

  5. A Simple Problem with Integers POJ - 3468 线段树区间修改+区间查询

    //add,懒标记,给以当前节点为根的子树中的每一个点加上add(不包含根节点) // #include <cstdio> #include <cstring> #includ ...

  6. A Simple Problem with Integers~POJ - 3468

    You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of op ...

  7. A Simple Problem with Integers POJ - 3468 (分块)

    题目链接:https://cn.vjudge.net/problem/POJ-3468 题目大意:区间加减+区间查询操作. 具体思路:本来是一个线段树裸题,为了学习分块就按照分块的方法做吧. 分块真的 ...

  8. C - A Simple Problem with Integers - poj 3468(区间更新)

    题意:有一个比较长的区间可能是100000.长度, 每个点都有一个值(值还比较大),现在有一些操作,C abc, 把区间a-b内全部加上c, Qab,求区间ab的值. 分析:很明显我们不可能对区间的每 ...

  9. POJ 3468(树状数组的威力)

    之前说过这是线段树的裸题,但是当看了http://kenby.iteye.com/blog/962159 这篇题解后我简直震惊了,竟然能如此巧妙地转化为用树状数组来处理,附上部分截图(最好还是进入原网 ...

随机推荐

  1. 第二百三十六天 how can I 坚持

    太冷了,羽绒服没帽子,冻的耳朵疼. 她今天没有上班,原来是调休了. 其实应该是想到点啥,就应该写下,到晚上写就又忘了,什么都不记得了,这就是个需求吧. 睡觉.

  2. 【多线程】Java并发编程:并发容器之CopyOnWriteArrayList(转载)

    原文链接: http://ifeve.com/java-copy-on-write/ Copy-On-Write简称COW,是一种用于程序设计中的优化策略.其基本思路是,从一开始大家都在共享同一个内容 ...

  3. C++11之使用或禁用对象的默认函数

    [C++11之使用或禁用对象的默认函数] C++11 允许显式地表明采用或拒用编译器提供的内置函数.例如要求类型带有默认构造函数,可以用以下的语法: 另一方面,也可以禁止编译器自动产生某些函数.如下面 ...

  4. emWin(ucGui) MULTIEDIT控件的按键响应处理 worldsing

    目前没有读过ucgui的源代码,通过应用代码测试出在FRAMEWIN的控件焦点顺序是样的: 按资源列表里创建的控件,默认将焦点落在第一个可接收焦点的控件,目前知道不可接收 焦点的控件有TEXT,在FR ...

  5. css3 动画demo

    1)http://www.yyyweb.com/demo/css-cokecan/inner.html 2)页面切换效果demo http://www.yyyweb.com/demo/page-tra ...

  6. JSP文件下载时文件名在ie和firefox下面文件名不一致极其超链接中文乱码的问题的改进

    response.setContentType("application/octet-stream;charset=UTF-8"); fileName=java.net.URLEn ...

  7. UI:页面传值、单例模式传值、属性传值、NSUserDefaults 数据持久化

    <单页面传值> 页面传值,从前向后传值,使用属性,在后一个页面定义属性,在前一个页面,用点语法,获得值,在适当的时候传值 页面传值,从后向前面传值,使用协议和代理,在后一个页面指定协议,定 ...

  8. 在WPF程序中使用摄像头兼谈如何使用AForge.NET控件(转)

    前言: AForge.NET 是用C#写的一个关于计算机视觉和人工智能领域的框架,它包括图像处理.神经网络.遗传算法和机器学习等.在C#程序中使用摄像头,我习惯性使用AForge.NET提供的类库.本 ...

  9. 备份服务器数据(IIS配置备份还原、任务计划、服务列表和APP)

    该脚本可以用来导出IIS配置.任务计划.服务列表和APP,同时支持Windows 2003和2008. #定义备份位置 $iisfolder = "d:\Backup_all\IIS&quo ...

  10. Spark MLlib Deep Learning Convolution Neural Network (深度学习-卷积神经网络)3.1

    3.Spark MLlib Deep Learning Convolution Neural Network (深度学习-卷积神经网络)3.1 http://blog.csdn.net/sunbow0 ...