题意:区间add,区间求和。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 100000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
LL a[MAXN];
LL sum[MAXN << 2];
LL lazy[MAXN << 2];
void build(int id, int L, int R){
if(L == R){
sum[id] = a[L];
}
else{
int mid = L + (R - L) / 2;
build(id << 1, L, mid);
build(id << 1 | 1, mid + 1, R);
sum[id] = sum[id << 1] + sum[id << 1 | 1];
}
}
void pushdown(int id, int L, int R){
if(lazy[id]){
lazy[id << 1] += lazy[id];
lazy[id << 1 | 1] += lazy[id];
int mid = L + (R - L) / 2;
sum[id << 1] += (mid - L + 1) * lazy[id];
sum[id << 1 | 1] += (R - mid) * lazy[id];
lazy[id] = 0;
}
}
void update(int l, int r, int id, int L, int R, LL v){
if(l <= L && R <= r){
lazy[id] += v;
sum[id] += (R - L + 1) * v;
}
else{
pushdown(id, L, R);
int mid = L + (R - L) / 2;
if(l <= mid) update(l, r, id << 1, L, mid, v);
if(r > mid) update(l, r, id << 1 | 1, mid + 1, R, v);
sum[id] = sum[id << 1] + sum[id << 1 | 1];
}
}
LL query(int l, int r, int id, int L, int R){
if(l <= L && R <= r){
return sum[id];
}
pushdown(id, L, R);
int mid = L + (R - L) / 2;
LL ans = 0;
if(l <= mid) ans += query(l, r, id << 1, L, mid);
if(r > mid) ans += query(l, r, id << 1 | 1, mid + 1, R);
return ans;
}
int main(){
int N, Q;
scanf("%d%d", &N, &Q);
for(int i = 1; i <= N; ++i){
scanf("%lld", &a[i]);
}
build(1, 1, N);
while(Q--){
char cc;
int a, b;
getchar();
scanf("%c%d%d", &cc, &a, &b);
if(cc == 'C'){
int c;
scanf("%d", &c);
update(a, b, 1, 1, N, (LL)c);
}
else{
printf("%lld\n", query(a, b, 1, 1, N));
}
}
return 0;
}

  

POJ - 3468 A Simple Problem with Integers (线段树区间更新---间接修改)的更多相关文章

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

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

  2. (简单) 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 ...

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

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

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

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

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

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

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

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

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

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

  8. POJ 3468 A Simple Problem with Integers 线段树 区间更新

    #include<iostream> #include<string> #include<algorithm> #include<cstdlib> #i ...

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

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

随机推荐

  1. FineReport帆软报表需求:根据url传递过来的参数值决定显示隐藏列

    需求:角色id传递到报表页面中,然后根据角色id,决定隐藏第1列,显示第2-4列,还是隐藏第2-4列,显示第1列. 解决方法:

  2. 六、linux基础-计算机网络_线程_进程

    6 计算机网络-线程和进程6.1 TCP/IP协议 TCP/IP是Unix/Linux世界的网络基础,在某种意义上,Unix网络就是Tcp/ip,而且Tcp/ip就是网络互连的标准他不是一个独立的协议 ...

  3. Systemverilog for design 笔记(一)

    转载请标明出处 一.     System Verilog 声明的位置 1.       包(packages) Verilog要求局部声明: variables, nets, tasks and f ...

  4. java基础复习-自定义注解4(结合JDBC技术,打造类表映射微框架)

    写在前面: 1.该框架为自己所写的第一个框架类产品,可能有着许多不足的地方,读者可以到评论区指出.同时,该微框架的源码也会开源至博客中,够后来的学习者借鉴.由于该框架逻辑结构稍些复杂,不可能花大量篇幅 ...

  5. 人物 - Larry Elison

    甲骨文公司创始人 甲骨文公司首席執行官 狂人,偏执狂 曾说:"Winning is not enough. All others must lose" Only the paran ...

  6. 本周总结(19年暑假)—— Part7

    日期:2019.8.25 博客期:113 星期日

  7. 应用间的API访问如何认证?

    任何一个一个应用要访问另一个应用的API,需要首先到开放平台获取访问accesskey, 然后访问目标应用,目标应用中先检查来源访问token是否已存在缓存中,不存在需要去开放平台校验accesske ...

  8. css 图形样式

    参考:https://css-tricks.com/examples/ShapesOfCSS/

  9. Spring注解@ConfigurationPropertie

    @ConfigurationPropertie作用 参考的博客 springboot中@ConfigurationProperties注解的工作原理 @ConfigurationProperties是 ...

  10. JS监听手机物理返回键,返回到指定页面

    pushHistory(); window.addEventListener("popstate", function(e) { window.location = data.in ...