链接:

http://poj.org/problem?id=3468

代码:

 #include<stdio.h>
#include<algorithm>
#include<stdlib.h>
using namespace std; #define Lson r<<1
#define Rson r<<1|1 const int N = 1e5+; struct SegmentTree
{
int L, R;
long long sum, e;
int Mid()
{
return (L+R)>>;
}
int len()
{
return R-L+;
}
}a[N<<]; void BuildSegTree(int r, int L, int R)
{
a[r].L=L, a[r].R=R;
a[r].e=; if(L==R)
{
scanf("%lld", &a[r].sum);
return ;
} BuildSegTree(Lson, L, a[r].Mid());
BuildSegTree(Rson, a[r].Mid()+, R); a[r].sum = a[Lson].sum + a[Rson].sum;
}
void PushDown(int r)
{
a[Lson].sum += a[r].e*a[Lson].len();
a[Lson].e += a[r].e;
a[Rson].sum += a[r].e*a[Rson].len();
a[Rson].e += a[r].e; a[r].e=;
}
void Update(int r, int L, int R, int e)
{
a[r].sum += (R-L+)*e; if(a[r].L==L && a[r].R==R)
{
a[r].e += e;
return ;
} PushDown(r); if(R<=a[r].Mid())
Update(Lson, L, R, e);
else if(L>a[r].Mid())
Update(Rson, L, R, e);
else
{
Update(Lson, L, a[r].Mid(), e);
Update(Rson, a[r].Mid()+, R, e);
}
}
long long Query(int r, int L, int R)
{
if(a[r].L==L && a[r].R==R)
return a[r].sum; PushDown(r); if(R<=a[r].Mid())
return Query(Lson, L, R);
else if(L > a[r].Mid())
return Query(Rson, L, R);
else
{
long long Lsum = Query(Lson, L, a[r].Mid());
long long Rsum = Query(Rson, a[r].Mid()+, R); return Lsum+Rsum;
}
} int main()
{
int n, m;
while(scanf("%d%d", &n, &m)!=EOF)
{
BuildSegTree(, , n); while(m--)
{
char s[];
int L, R, e; scanf("%s", s); if(s[]=='Q')
{
scanf("%d%d", &L, &R);
printf("%lld\n", Query(, L, R));
}
else
{
scanf("%d%d%d", &L, &R, &e);
Update(, L, R, e);
}
}
}
return ;
}

(线段树模板)A Simple Problem with Integers --POJ--3468的更多相关文章

  1. 线段树---poj3468 A Simple Problem with Integers:成段增减:区间求和

    poj3468 A Simple Problem with Integers 题意:O(-1) 思路:O(-1) 线段树功能:update:成段增减 query:区间求和 Sample Input 1 ...

  2. 线段树:POJ3468-A Simple Problem with Integers(线段树注意事项)

    A Simple Problem with Integers Time Limit: 10000MS Memory Limit: 65536K Description You have N integ ...

  3. A Simple Problem with Integers poj 3468 多树状数组解决区间修改问题。

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

  4. 【POJ3468】【zkw线段树】A Simple Problem with Integers

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

  5. C - A Simple Problem with Integers POJ - 3468 线段树模版(区间查询区间修改)

    参考qsc大佬的视频 太强惹 先膜一下 视频在b站 直接搜线段树即可 #include<cstdio> using namespace std; ; int n,a[maxn]; stru ...

  6. A Simple Problem with Integers POJ - 3468 (线段树)

    思路:线段树,区间更新,区间查找 #include<iostream> #include<vector> #include<string> #include< ...

  7. A Simple Problem with Integers~POJ - 3468

    You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of op ...

  8. A Simple Problem with Integers POJ - 3468 (分块)

    题目链接:https://cn.vjudge.net/problem/POJ-3468 题目大意:区间加减+区间查询操作. 具体思路:本来是一个线段树裸题,为了学习分块就按照分块的方法做吧. 分块真的 ...

  9. 【算法系列学习】线段树 区间修改,区间求和 [kuangbin带你飞]专题七 线段树 C - A Simple Problem with Integers

    https://vjudge.net/contest/66989#problem/C #include<iostream> #include<cstdio> #include& ...

  10. A Simple Problem with Integers POJ - 3468 线段树区间修改+区间查询

    //add,懒标记,给以当前节点为根的子树中的每一个点加上add(不包含根节点) // #include <cstdio> #include <cstring> #includ ...

随机推荐

  1. 2018 Jar_Feb_Newwords

    检测钩子程序 开发一个检测钩子程序的工具 - 豆丁网http://www.docin.com/p-1363993661.html pdf掺杂病毒的方法 Java的:xml文件中跳过的二进制数据在解析 ...

  2. oracle老是出现监听错误

    解决方法之一: 点击开始-->选择程序--->选中你安装的oracle版本-->选中配置与移植工具-->选中Net Configuration Assistant-->在 ...

  3. css样式占位和不占位隐藏元素的方法

    不占位隐藏:display:none; 占位隐藏:visibility:hidden;

  4. 刚刚明白了for循环写三角形

    for(int a = 15; a >=1; a--) { for(int b = a - 1; b >=0; b--) { System.out.print("A") ...

  5. keras—神经网络CNN—CIFAR_10图像识别

    1 from keras.datasets import cifar10 from keras.utils import np_utils import matplotlib.pyplot as pl ...

  6. python版本安装

    目的 本文目的在于,对于不熟悉Python的人,教你: 1. 从哪里找到 可以下载到 各种版本的 包括Python 2.x和Python 3.x的 最新版本的 Python. 高手请无视之. 2.以及 ...

  7. IBM MQ + WebSphere + Spring JMS配置方法

    IBM MQ + WebSphere + Spring JMS配置方法  首先要在WAS里面配置IBM MQ作为JMS消息的提供者,在WAS管理控制台: Resources->JMS Provi ...

  8. Loadrunner12.5-录制http://www.gw.com.cn/网页时提示“SSL身份验证失败”错误,这是为什么呢?

    问题:LR产品,录制http://www.gw.com.cn/ 网页时提示下图错误,这是为什么呢? 请在如下recording options中选择正确的SSL版本,再进行录制. 注:如何确定那个SS ...

  9. Rendering Resources

    1. Real-Time Rendering Resources http://www.realtimerendering.com/ 2. Books on Amazon http://www.ama ...

  10. VMware下的Linux系统中Windows的共享目录,不支持创建软连接

    [问题]  在编译VMware下的Linux系统对从Windows中共享过来的文件,进行编译的时候,遇到:  ln: creating symbolic link XXXXXX : Operation ...