一个有初值的数列、区间加、区间查

用线段树直接水过

然而并没有1A,主要是做题太快没看规模结果没注意线段树要用longlong建

卧槽怎么可以这么坑爹,害得我看见wa心慌了,还以为连线段树都要跪

一开始在写下传(MDZZ)然后发现没什么操作就删了

 #include <cstdio>
#include <iostream>
#define mid (l+r)/2
long long t[],tr[];
int n,m;
void add(int now,int l,int r,int x,int y)
{
t[now]+=y;
if(l==r)
return;
if(x<=mid)
add(now*,l,mid,x,y);
else
add(now*+,mid+,r,x,y);
}
void plus(int now,int l,int r,int x,int y,int z)
{
if(l==x && r==y)
{
tr[now]+=z;
return;
}
if(x<=mid)
plus(now*,l,mid,x,std::min(y,mid),z);
if(y>mid)
plus(now*+,mid+,r,std::max(x,mid+),y,z);
t[now]=t[now*]+tr[now*]*(mid-l+)+t[now*+]+tr[now*+]*(r-mid);
}
long long que(int now,int l,int r,int x,int y)
{
if(l==x && r==y)
return t[now]+tr[now]*(r-l+);
long long sum=(y-x+)*tr[now];
if(x<=mid)
sum+=que(now*,l,mid,x,std::min(y,mid));
if(y>mid)
sum+=que(now*+,mid+,r,std::max(x,mid+),y);
return sum;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
int x;
scanf("%d",&x);
add(,,n,i,x);
}
for(int i=;i<=m;i++)
{
char ch=getchar();
for(;ch!='C' && ch!='Q';ch=getchar());
if(ch=='C')
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
plus(,,n,x,y,z);
}
else
{
int x,y;
scanf("%d%d",&x,&y);
printf("%lld\n",que(,,n,x,y));
}
}
return ;
}

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

  1. BZOJ-3212 Pku3468 A Simple Problem with Integers 裸线段树区间维护查询

    3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 128 MB Submit: 1278 Sol ...

  2. bzoj3212 Pku3468 A Simple Problem with Integers 线段树

    3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 2046  So ...

  3. BZOJ3212: Pku3468 A Simple Problem with Integers(线段树)

    3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 2530  So ...

  4. BZOJ3212 Pku3468 A Simple Problem with Integers 题解

    题目大意: 一个数列,有两个操作:1.修改操作,将一段区间内的数加上c:2.查询操作,查询一段区间内的数的和. 思路: 线段树裸题,区间修改.区间查询,维护和以及加上的数,由于无序,不需要向下推标记, ...

  5. 【分块】【线段树】bzoj3212 Pku3468 A Simple Problem with Integers

    线段树入门题…… 因为poj原来的代码莫名RE,所以丧病地写了区间修改的分块…… 其实就是块上打标记,没有上传下传之类. #include<cstdio> #include<cmat ...

  6. 3212: Pku3468 A Simple Problem with Integers

    3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 1053  So ...

  7. bzoj 3212 Pku3468 A Simple Problem with Integers

    3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec  Memory Limit: 128 MB Description You ...

  8. bzoj 3212 Pku3468 A Simple Problem with Integers 线段树基本操作

    Pku3468 A Simple Problem with Integers Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 2173  Solved:  ...

  9. [BZOJ3212][POJ3468]A Simple Problem with Integers

    题目大意: 维护一个长度为$n(n\leq100000)$的数列,支持区间加.区间求和两种操作,操作共$m(m\leq100000)$次. 思路: Splay区间操作. #include<cst ...

随机推荐

  1. Bash 的 no-fork 优化

    我们知道,Bash 在执行一个外部命令时,会先 fork() 一个子进程,然后在子进程里面执行 execve() 去加载那个外部程序.fork 子进程是会耗性能的,所以 Bash 会在下面几种情况下不 ...

  2. javascript数据结构与算法---检索算法

    查找数据有2种方式,顺序查找和二分查找.顺序查找适用于元素随机排列的列表.二分查找适用于元素已排序的列表.二分查找效率更高,但是必须是已经排好序的列表元素集合. 一:顺序查找 顺序查找是从列表的第一个 ...

  3. php 类编写

    1.没有重载的函数,实现重载函数只能通过func_get_args()这种方式进行转化 2.每个变量只能单独命名为控制权限(private.protected.public) 3.php反射类带参数 ...

  4. Nginx反向代理+keepalived

    环境两台LB(nginx).两台web(nginx/apache都行) 安装httpd web01 [root@web01 /]# /etc/init.d/iptables stop iptables ...

  5. FreeImage编译及遇到问题解决

    FreeImage编译及遇到问题解决 1.下载freeImage源码包 wget http://downloads.sourceforge.net/freeimage/FreeImage3170.zi ...

  6. Android Killer工具用法

    一.工程信息 工程信息主要是解析的AndroidManifest文件 二.工程管理器 三.配置插入代码 在代码中点右键就可以一键插入代码了 四.字符串搜索功能 支持正则, 比jeb搜索功能强大 来自为 ...

  7. C#静态常量和动态常量的区别

    C#拥有两种不同的常量:静态常量(compile-time constants)和动态常量(runtime  constants).它们有不同的特性,错误的使用不仅会损失效率,还可能造成错误.相比之下 ...

  8. VC++ 制作一个简易的控制台时钟应用

    1.下载EasyX Library for C++ (http://www.easyx.cn/) 直接下载:EasyX_20151015(beta) EasyX 绘图库目前支持 Visual C++ ...

  9. C#反射机制 (转载)

    转载:原文出处      http://www.cnblogs.com/binfire/archive/2013/01/17/2864887.html 一:反射的定义 审查元数据并收集关于它的类型信息 ...

  10. 16进制ascii码转化为对应的字符,付ipmitool查询硬件信息

    最近工作需要在用ipmitool查询服务器硬件信息.ipmitool查询硬件信息 比如电源,使用命令: 获取PSU0信息:Ipmitool raw 0x3a 0x71 0x00: 获取PSU1信息:I ...