poj 3468 A Simple Problem with Integers(线段树 插线问线)
#include<iostream>
#include<stdio.h>
#include<string.h>
#define NN 2500000 using namespace std; typedef long long LL;
struct node
{
LL l,r,sum,flag;
} N[NN]; void build(LL l,LL r,LL i)
{
LL mid=(l+r)>>1;
N[i].flag=0;
N[i].l=l;
N[i].r=r;
N[i].sum=0;
if(l==r)
{
scanf("%lld",&N[i].sum);
return ;
}
build(l,mid,i*2);
build(mid+1,r,i*2+1);
N[i].sum=N[i*2].sum+N[i*2+1].sum;
} void renew(LL i,LL l,LL r,LL k)
{
LL mid=(N[i].l+N[i].r)>>1;
if(N[i].l==l&&N[i].r==r)
{
N[i].flag+=k;
return ;
}
N[i].sum+=(r-l+1)*k;
if(mid<l) renew(i*2+1,l,r,k);
else if(mid>=r)renew(i*2,l,r,k);
else
{
renew(i*2,l,mid,k);
renew(i*2+1,mid+1,r,k);
}
} LL query(LL i,LL l,LL r)
{
LL mid=(N[i].l+N[i].r)>>1;
if(l==N[i].l&&r==N[i].r)
{
return N[i].sum+(r-l+1)*N[i].flag;
}
if(N[i].flag)
{
N[i*2].flag+=N[i].flag;
N[i*2+1].flag+=N[i].flag;
N[i].sum+=(N[i].r-N[i].l+1)*N[i].flag;
N[i].flag=0;
}
if(l>mid) return query(i*2+1,l,r);
else if(r<=mid) return query(i*2,l,r);
else
{
return query(i*2+1,mid+1,r)+query(i*2,l,mid);
}
} int main()
{
LL n,m,suzi,a,b,i;
char s[5];
while(scanf("%lld %lld",&n,&m)!=EOF)
{
build(1,n,1);
// prLLf("sdd=%lld\n",N[8].sum);
// return 0;
for(i=1; i<=m; i++)
{
scanf("%s",s);
// return 0;
if(s[0]=='C')
{
LL a,b,c;
scanf("%lld %lld %lld",&a,&b,&c);
renew(1,a,b,c);
}
else
{
LL a,b;
scanf("%lld %lld",&a,&b);
printf("%lld\n",query(1,a,b));
}
}
}
return 0;
}
poj 3468 A Simple Problem with Integers(线段树 插线问线)的更多相关文章
- 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 ...
- 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 ...
- poj 3468 A Simple Problem with Integers 线段树第一次 + 讲解
A Simple Problem with Integers Description You have N integers, A1, A2, ... , AN. You need to deal w ...
- [POJ] 3468 A Simple Problem with Integers [线段树区间更新求和]
A Simple Problem with Integers Description You have N integers, A1, A2, ... , AN. You need to deal ...
- poj 3468 A Simple Problem with Integers (线段树区间更新求和lazy思想)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 75541 ...
- POJ 3468 A Simple Problem with Integers(线段树 成段增减+区间求和)
A Simple Problem with Integers [题目链接]A Simple Problem with Integers [题目类型]线段树 成段增减+区间求和 &题解: 线段树 ...
- POJ 3468 A Simple Problem with Integers //线段树的成段更新
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 59046 ...
- poj 3468 A Simple Problem with Integers 线段树加延迟标记
A Simple Problem with Integers Description You have N integers, A1, A2, ... , AN. You need to deal ...
- poj 3468 A Simple Problem with Integers 线段树区间更新
id=3468">点击打开链接题目链接 A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072 ...
- POJ 3468 A Simple Problem with Integers(线段树,区间更新,区间求和)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 67511 ...
随机推荐
- Linux 下 GCC 编译共享库控制导出函数的方法
通过一些实际项目的开发,发现这样一个现象,在 Windows 下可以通过指定 __declspec(dllexport) 定义来控制 DLL(动态链接库)中哪些函数可以导出,暴露给其他程序链接使用,哪 ...
- delphi使用IdHTTP模拟提交页面方法总结
http://blog.csdn.net/lxdcyh/article/details/3986800 1.拖入TIdHTTP控件,HandleRedirect设为True,否则可能会出现HTTP 3 ...
- Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) E. Vasya and Good Sequences
题目链接 官网题解写的好清楚,和昨晚Aguin说的一模一样…… 这题只和每个数1的个数有关,设每个数1的个数的数组为$b$,就是首先一段如果是好的,要满足两个条件: 1.这一段$b$数组和为偶数,因为 ...
- (7)C#连DB2---oledb方式
1安装客户端 安装DbVisualizer Free 客户端软件 2编目 用 win+r 输入 db2cmd 启动命令行 要远程操作数据库,首先要进行编目,分三个步骤: 1. 在客户端建立服务器端数 ...
- Struts2的标签三大类是什么?
Struts2 标签 一 Struts标签的简介: Struts2 自己封装了一套标签,比 JSTL 强大,而且与 Struts2 中的其他功能无缝结合. 当然 Strust2 标签的内容很多,随着版 ...
- 如何细粒度地控制你的MyBatis二级缓存(mybatis-enhanced-cache插件实现)
前几天网友chanfish 给我抛出了一个问题,笼统地讲就是如何能细粒度地控制MyBatis的二级缓存问题,酝酿了几天,觉得可以写个插件来实现这个这一功能.本文就是从问题入手,一步步分析现存的MyBa ...
- gdb源码安装过程中的问题:no termcap library found
gdb使用源码安装的时候遇到错误:no termcap library found ./configure --> make --> make install 解决办法,下载termca ...
- webrtc初探
0.闲来无事,想研究webrtc,看了一些网上的文章之后,觉得谬误较多,以讹传讹的比较多,自己试验了一把,记录一下. 官网的写的教程在实践中也觉得不用那么复杂,有种落伍与繁冗的感觉. 1.我想看的是w ...
- 【C#】高级语言特有的单例模式
public class Singleton { private Singleton () { } // 变量标记为 readonly.第一次引用类的成员或创建实例时,仅仅实例化一次instance对 ...
- 设计模式入门之原型模式Prototype
//原型模式:用原型实例指定创建对象的种类,并通过拷贝这些原型创建新的对象 //简单来说,当进行面向接口编程时,假设须要复制这一接口对象时.因为不知道他的详细类型并且不能实例化一个接口 //这时就须要 ...