Description

给出了一个序列,你需要处理如下两种询问。

"C abc"表示给[a, b]区间中的值全部增加c (-10000 ≤ c ≤ 10000)。

"Q ab" 询问[a, b]区间中所有值的和。

Input

第一行包含两个整数N, Q。1≤ N,Q ≤ 100000.

第二行包含n个整数,表示初始的序列A (-1000000000 ≤ Ai ≤1000000000)。

接下来Q行询问,格式如题目描述。

Output

对于每一个Q开头的询问,你需要输出相应的答案,每个答案一行。

Sample Input

10 5
1 2 3 4 5 6 7 8 9 10
Q 4 4
Q 1 10
Q 2 4
C 3 6 3
Q 2 4

Sample Output

4
55
9
15

依旧是线段树操作,注意数据范围用long long

 //#include<bits/stdc++.h>//POJ不吃这条
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
struct NODE{
int l,r;
long long sum,t;
}node[];
int data[];
int n,m;
void Build(int num,int left,int right){//以num为根建线段树
node[num].l=left;
node[num].r=right;
if(left==right){
node[num].sum=data[left];
return;
}
int mid=(left+right)/;
Build(num*,left,mid);
Build(num*+,mid+,right);
node[num].sum=node[num*].sum+node[num*+].sum;
return;
} void update(int num){//标记下传
node[num<<].t+=node[num].t;
node[num*+].t+=node[num].t;
node[num<<].sum+=(node[num<<].r-node[num<<].l+)*node[num].t;
node[num*+].sum+=(node[num*+].r-node[num*+].l+)*node[num].t;
node[num].t=;
return;
}
long long qu(int l,int r,int num){//求和
if(node[num].r<l || node[num].l>r)return ;
if(node[num].l>=l && node[num].r<=r)return node[num].sum;
if(node[num].t)update(num);
return qu(l,r,num<<)+qu(l,r,num*+);
}
void change(int l,int r,int c,int num){
if(node[num].r<l || node[num].l>r)return;
if(node[num].l>=l && node[num].r<=r){
node[num].sum+=c*(node[num].r-node[num].l+);
node[num].t+=c;
return;
}
if(node[num].t)update(num);
change(l,r,c,num<<);
change(l,r,c,num*+);
node[num].sum=node[num<<].sum+node[num*+].sum;
return;
}
int main(){
scanf("%d%d",&n,&m);
int i,j;
for(i=;i<=n;i++)scanf("%d",&data[i]);
Build(,,n);
char s;
int a,b,c;
for(i=;i<=m;i++)
{
cin>>s;
if(s=='C'){
scanf("%d%d%d",&a,&b,&c);
change(a,b,c,);
}
if(s=='Q'){
scanf("%d%d",&a,&b);
printf("%lld\n",qu(a,b,));
}
}
return ;
}

因为printf里忘了用lld而WA,纠结了半个多小时才意识到问题所在←又犯了这种蠢错误

POJ3468 A Simple Problem with Integers的更多相关文章

  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: 5000MS   Memory Limit: 131072K Total Submissions: 92127   ...

  3. poj------(3468)A Simple Problem with Integers(区间更新)

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

  4. POJ3468 A Simple Problem with Integers 【段树】+【成段更新】

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

  5. poj3468 A Simple Problem with Integers (树状数组做法)

    题目传送门 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 1 ...

  6. POJ3468 A Simple Problem with Integers —— 线段树 区间修改

    题目链接:https://vjudge.net/problem/POJ-3468 You have N integers, A1, A2, ... , AN. You need to deal wit ...

  7. poj3468 A Simple Problem with Integers(线段树区间更新)

    https://vjudge.net/problem/POJ-3468 线段树区间更新(lazy数组)模板题 #include<iostream> #include<cstdio&g ...

  8. [POJ3468] A Simple Problem with Integers (Treap)

    题目链接:http://poj.org/problem?id=3468 这题是线段树的题,拿来学习treap. 不旋转的treap. #include <cstdio> #include ...

  9. POJ3468 A Simple Problem with Integers(线段树延时标记)

    题目地址http://poj.org/problem?id=3468 题目大意很简单,有两个操作,一个 Q a, b 查询区间[a, b]的和 C a, b, c让区间[a, b] 的每一个数+c 第 ...

  10. POJ-3468 A Simple Problem with Integers Splay Tree区间练习

    题目链接:http://poj.org/problem?id=3468 以前用线段树做过,现在用Splay Tree A了,向HH.kuangbin.cxlove大牛学习了各种Splay各种操作,,, ...

随机推荐

  1. 洛谷 1016 / codevs 1046 旅行家的预算

    https://www.luogu.org/problem/show?pid=1016 http://codevs.cn/problem/1046/ 题目描述 Description 一个旅行家想驾驶 ...

  2. Session一次错误记录

    /// <summary>        /// 验证登录状态是否已失效        /// </summary>        /// <returns>< ...

  3. UDP的坏处

    众所周知,UDP是一个面向无连接的协议.通信时不可靠的.这就会出现一些问题 (1)数据报丢失 因为是无连接,的所以可以用recvfrom和sendto来接收和发送消息,如果socket是阻塞的,那么当 ...

  4. Angular权威指南学习笔记(转)

    http://www.cnblogs.com/lzhp/p/4000741.html 第一章.        初识Angular——Angular是MVW的Js框架. 第二章.        数据绑定 ...

  5. ReactNative真机运行指南

    ReactNative真机运行指南 注意在iOS设备上运行React Native应用需要一个Apple Developer account并且把你的设备注册为测试设备.本向导只包含React Nat ...

  6. iis7配置网站容易出现的问题(转)

    来源: http://www.cnblogs.com/5426z/articles/4865022.html 1.64位操作系统 access数据库提示:未在本地计算机上注册"Microso ...

  7. 弱占优策略--Weakly Dominant Strategy

    Weakly Dominant Strategy Equilibrium(均衡). 先说弱占优.一个策略弱占优就是说,无论其他人采取什么样的策略,这个策略的回报都大于等于其他策略的回报.如果所有人都使 ...

  8. android之拍照与摄像

    拍照和摄像的意图很简答,这里直接贴代码 布局文件 <?xml version="1.0" encoding="utf-8"?> <Linear ...

  9. Oracle在中文环境下出现乱码解决办法

       zysong.ttf下载是一款oracle字体乱码解决工具,实质于缺乏中文字体包! 01情况的例子 02情况的例子 01.在开始安装的时候出现乱码 下载zysong.ttf,unzip 解压 一 ...

  10. “Ceph浅析”系列之七——关于Ceph的若干想法

    本篇文章的内容,主要是笔者在调研分析Ceph过程中产生的一些思考.因为其中的内容比较自由发散,且大多是笔者的个人见解,故此另启一文进行讨论. 关于Ceph的性能 目前为止,本系列的文章中没有涉及到Ce ...