POJ 3468 A Simple Problem with Integers(树状数组)
题目链接: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(树状数组)的更多相关文章
- A Simple Problem with Integers(树状数组HDU4267)
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- HDU 4267 A Simple Problem with Integers --树状数组
题意:给一个序列,操作1:给区间[a,b]中(i-a)%k==0的位置 i 的值都加上val 操作2:查询 i 位置的值 解法:树状数组记录更新值. 由 (i-a)%k == 0 得知 i%k == ...
- POJ3468 A Simple Problem With Integers 树状数组 区间更新区间询问
今天学了很多关于树状数组的技巧.一个是利用树状数组可以简单的实现段更新,点询问(二维的段更新点询问也可以),每次修改只需要修改2个角或者4个角就可以了,另外一个技巧就是这题,原本用线段树做,现在可以用 ...
- POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询)
POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询) 题意分析 注意一下懒惰标记,数据部分和更新时的数字都要是long long ,别的没什么大 ...
- poj 3468 A Simple Problem with Integers 【线段树-成段更新】
题目:id=3468" target="_blank">poj 3468 A Simple Problem with Integers 题意:给出n个数.两种操作 ...
- 线段树(成段更新) POJ 3468 A Simple Problem with Integers
题目传送门 /* 线段树-成段更新:裸题,成段增减,区间求和 注意:开long long:) */ #include <cstdio> #include <iostream> ...
- poj 3468 A Simple Problem with Integers(线段树+区间更新+区间求和)
题目链接:id=3468http://">http://poj.org/problem? id=3468 A Simple Problem with Integers Time Lim ...
- POJ 3468 A Simple Problem with Integers(线段树功能:区间加减区间求和)
题目链接:http://poj.org/problem?id=3468 A Simple Problem with Integers Time Limit: 5000MS Memory Limit ...
- POJ 3468 A Simple Problem with Integers(分块入门)
题目链接:http://poj.org/problem?id=3468 A Simple Problem with Integers Time Limit: 5000MS Memory Limit ...
- 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 ...
随机推荐
- Aspose 导出excel小demo
//转为pdf private void CelltoPDF(string cellPath, string pdfPath) { Workbo ...
- ascx aspx ashx asmx 文件的作用
ascx aspx ashx asmx 文件的作用 ascx: Ascx 是给予Web的用户控件(UserControl),一般是用来重用的,不能直接被访问只能插入aspx页面呈现.头部文件<% ...
- C# ASP .NET WEB方向和WPF方向,我该如何去选择
一个2012年南航毕业学软件的学生,该如何去选择我的职业方向? 2011年11分月份,我被老师介绍在南京珠江路华丽国际大厦工作,开发一个大型国际物流平台,公司的开发人员比较少,设计网站的是高校的老师, ...
- 1833: [ZJOI2010]count 数字计数 - BZOJ
Description给定两个正整数a和b,求在[a,b]中的所有整数中,每个数码(digit)各出现了多少次.Input输入文件中仅包含一行两个整数a.b,含义如上所述.Output输出文件中包含一 ...
- Jquery 判断浏览器类型
$(function() { //FireFox2及以上 if ($.browser.MozillaSideBar && $.browser.version >= "1 ...
- [CF]codeforces round 369(div2)
*明早起来再贴代码 A [题意] 给定n*5的方格 将横向的相邻两个变成+输出 [题解] ... B [题意] 一个n*n的正整数矩阵,有且仅有一个数为0 ,在这个位置填上一个数,使得每一列的和 每一 ...
- Webbrowser 取消下载提示框
在使用Webbrowser抓取网页信息时,碰到需要下载文件,这时需要用户介入操作,如何避免: 首先引进 [DllImport("urlmon.dll", CharSet = Cha ...
- 正确使用stl vecotr erase函数
erase函数要么删作指定位置loc的元素,要么删除区间[start, end)的所有元素. 返回值是指向删除的最后一个元素的下一位置的迭代器 Parameters All parameters ar ...
- RAD项目结构
- 移动开发之meta篇
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable= ...