题目链接

  题目是对一个数组,支持两种操作

    操作C:对下标从a到b的每个元素,值增加c;

    操作Q:对求下标从a到b的元素值之和。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
typedef long long LL; const int maxn=1e5+;
LL lazy[maxn<<],sum[maxn<<]; void push_up(int rt)
{
sum[rt]=sum[rt<<]+sum[rt<<|];
}
void push_down(int rt,int len)
{
if(lazy[rt]==) return ;
lazy[rt<<]+=lazy[rt];
lazy[rt<<|]+=lazy[rt];
sum[rt<<]+=lazy[rt]*(len-(len>>));
sum[rt<<|]+=lazy[rt]*(len>>);
lazy[rt]=;
} void build(int rt,int l,int r)
{
if(l==r)
{
lazy[rt]=;
scanf("%lld",&sum[rt]);
return ;
}
int mid=(l+r)>>;
build(rt<<,l,mid);
build(rt<<|,mid+,r);
push_up(rt);
} void update(int rt,int l,int r,int ul,int ur,int v)
{
if(ul<=l&&r<=ur)
{
lazy[rt]+=v;
sum[rt]+=(r-l+)*v;
return ;
}
push_down(rt,r-l+);
int mid=(l+r)>>;
if(ul<=mid) update(rt<<,l,mid,ul,ur,v);
if(ur>mid) update(rt<<|,mid+,r,ul,ur,v);
push_up(rt);
} LL query(int rt,int l,int r,int ql,int qr)
{
if(ql<=l&&r<=qr) return sum[rt];
int mid=(l+r)>>;
push_down(rt,r-l+);
LL ret=;
if(ql<=mid) ret+=query(rt<<,l,mid,ql,qr);
if(qr>mid) ret+=query(rt<<|,mid+,r,ql,qr);
return ret;
} int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
build(,,n);
while(m--)
{
char op[];
scanf("%s",op);
if(op[]=='Q')
{
int l,r;
scanf("%d%d",&l,&r);
printf("%lld\n",query(,,n,l,r));
}
else
{
int l,r,c;
scanf("%d%d%d",&l,&r,&c);
update(,,n,l,r,c);
}
}
}
}

poj 3468 : A Simple Problem with Integers 【线段树 区间修改】的更多相关文章

  1. POJ 3468 A Simple Problem with Integers 线段树区间修改

    http://poj.org/problem?id=3468 题目大意: 给你N个数还有Q组操作(1 ≤ N,Q ≤ 100000) 操作分为两种,Q A B 表示输出[A,B]的和   C A B ...

  2. 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 ...

  3. 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 ...

  4. [POJ] 3468 A Simple Problem with Integers [线段树区间更新求和]

    A Simple Problem with Integers   Description You have N integers, A1, A2, ... , AN. You need to deal ...

  5. poj 3468 A Simple Problem with Integers (线段树区间更新求和lazy思想)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 75541   ...

  6. poj 3468 A Simple Problem with Integers 线段树区间更新

    id=3468">点击打开链接题目链接 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072 ...

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

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 67511   ...

  8. (简单) POJ 3468 A Simple Problem with Integers , 线段树+区间更新。

    Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. On ...

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

    题目地址:POJ 3468 打了个篮球回来果然神经有点冲动. . 无脑的狂交了8次WA..竟然是更新的时候把r-l写成了l-r... 这题就是区间更新裸题. 区间更新就是加一个lazy标记,延迟标记, ...

  10. POJ 3468 A Simple Problem with Integers(线段树区间更新,模板题,求区间和)

    #include <iostream> #include <stdio.h> #include <string.h> #define lson rt<< ...

随机推荐

  1. dd备份命令使用

    转载——dd 参数解释 1. if=文件名:输入文件名,缺省为标准输入.即指定源文件.< if=input file > 2. of=文件名:输出文件名,缺省为标准输出.即指定目的文件.& ...

  2. 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_01 File类_5_File类获取功能的方法

    获取的方法 GetAbsolutepath 传递一个相对路径进去,查看输出的结果 输出的还是绝对的路径 getPath 获取的就是构造方法中传递的路径,可以传递绝对路径也可以传递相对路径 实际上toS ...

  3. mysql数据库连接 application.properties

    # 数据库链接信息mysql.driver=com.mysql.cj.jdbc.Drivermysql.url=jdbc:mysql://localhost:3306/xxxx?characterEn ...

  4. python_001

    一.python开发1.python基础 -基础 -基本数据类型 -函数 -面向对象2.网络编程3.web框架 -用于写网站4.设计模式 + 算法

  5. 【BASIS系列】SAP /usr/sap//DVEBMGS00满了怎么处理

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[BASIS系列]SAP /usr/sap//D ...

  6. ios平台appstore不支持网页内嵌app解决方案

    苹果一直拒绝 UIWebView 内嵌 HTML5 页面的 iPhone.iPad APP应用上架到 App Store,建议这样的APP去做成Safari的Web应用.但是,苹果的审核人员只从界面. ...

  7. linux--初识别

    镜像网站 下载系统镜像 http://mirrors.163.com/ http://mirrors.sohu.com https://www.netcraft.com/ 命令大全 https://m ...

  8. hdu-4292.food(类dining网络流建图)

    Food Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  9. Spring Security框架入门

    1.Spring Security框架入门 1.1 Spring Security简介 Spring Security是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框 ...

  10. TimeUnit类 java.util.concurrent.TimeUnit

    TimeUnit是什么? TimeUnit是java.util.concurrent包下面的一个类,表示给定单元粒度的时间段 主要作用 时间颗粒度转换 延时 常用的颗粒度 TimeUnit.DAYS ...