题目链接

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

    操作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. leetcode-mid-Linked list-2 Add Two Numbers

    mycode 87.22% # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x) ...

  2. Linux驱动开发6——DDR内存分配

    1.kmalloc和kfree #include <linux/slab.h> void *kmalloc(size_t size, int flags); flag: GFP_ATOMI ...

  3. Sqlserver 中间表的操作

    去除列名重复 select rtrim(ltrim(a.Bank)) as Country, count(*) as Total from T_BASE_OWNER a left join T_BAS ...

  4. ubuntu 安装java1.8

    1.进入官网下载页面http://www.oracle.com/technetwork/java/javase/downloads/index.html 2.选择需要的版本,进入下载页面 下载 jdk ...

  5. Centos 下更改MySQL源数据存放目录(datadir)

    MySQL在安装完成之后,其源数据默认存放在 /var/lib/mysql/ 目录下,一般情况下,该目录在根目录下,由于Linux系统默认  根目录所在挂载的磁盘容量有限,随着生产数据的不断产生,该目 ...

  6. webpack前端模块打包器

    webpack前端模块打包器 学习网址: https://doc.webpack-china.org/concepts/ http://www.runoob.com/w3cnote/webpack-t ...

  7. 为什么说 Babel 将推动 JavaScript 的发展【转】

    Babel是一个转换编译器,它能将 ES6 转换成可以在浏览器中运行的代码.Babel 由来自澳大利亚的开发者Sebastian McKenzie创建.他的目标是使 Babel 可以处理 ES6 的所 ...

  8. jvm学习(2)JVM内存说明

    前言 一.类方法 类方法是静态方法,前面需要有static修饰符修饰.类方法内不能涉及有关变量的内容1.不能调用类的对象方法2.不能引用对象变量3.类方法不能被重写(覆盖)4.类方法不能使用super ...

  9. [2019杭电多校第二场][hdu6599]I Love Palindrome String(回文自动机&&hash)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6599 题目大意为求字符串S有多少个子串S[l,r]满足回文串的定义,并且S[l,(l+r)/2]也满足 ...

  10. 加密模块hashlib

    #coding=utf-8 import ConfigParser #配置文件模块 import hashlib #用于加密的模块 m = hashlib.md5() m.update(b'hello ...