题目链接

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

    操作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. MySQL高可用方案 MHA之一MHA安装

    MHA0.58安装 MHA(Master High Availability)由两部分组成:MHA Manager(管理节点)和MHA Node(数据节点).管理节点mha4mysql-manager ...

  2. BBED ORA-00600: internal error code, arguments: [16703], [1403], [20], [], [], [], [], [], [], [], [], []

    BBED模拟并修复 删除:$ORACLE_HOME/rdbms/admin/prvtsupp.plb SQL> alter database open;alter database open*E ...

  3. uid auid euid的区别

    关于euid suid guid,参考这篇很好的文章 uid auid euid的区别? initially: 最初地, 一开始地 jackson had initially bloodied his ...

  4. centos修改时区,同步时间

    查看当前系统时区 ls -la /etc/localtime 查看支持的时区 timedatectl list-timezones # 查看所有时区 timedatectl list-timezone ...

  5. Jmeter响应中中文乱码怎么解决?

    在jmeter的bin目录下有一个jmeter.properties的文件,打开它,搜索sampleresult.default.encoding,把它的注释打开,也就是把最前面的#去掉,改成samp ...

  6. 类Thread

    public final void join() throws InterruptedException /* * public final void join() * throws Interrup ...

  7. beego 注解路由无效问题分析

    问题描述:学习 beego 框架发现注解路由无效,除了不能找到路由外,未见任何异常. 问题解决:将配置文件中的 runmode 更改为 dev 模式. 问题分析: 如果没有设置过 runmode 不会 ...

  8. Spring Boot 之 Redis

    一.pom.xml引入依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifac ...

  9. 003--PowerDesigner创建索引与外键

    PowerDesigner创建索引与外键 一.创建索引 双击Table->Columns->创建索引 Step1:双击Table Step2:选择Columns->创建索引 弹出如下 ...

  10. MySQL里null与空值的辨析

    CREATE TABLE `test` ( `col1` VARCHAR( 10 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , `co ...