bzoj3212 pku3468 A Simple Problem with Integers
一个有初值的数列、区间加、区间查
用线段树直接水过
然而并没有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的更多相关文章
- 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 ...
- bzoj3212 Pku3468 A Simple Problem with Integers 线段树
3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2046 So ...
- BZOJ3212: Pku3468 A Simple Problem with Integers(线段树)
3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2530 So ...
- BZOJ3212 Pku3468 A Simple Problem with Integers 题解
题目大意: 一个数列,有两个操作:1.修改操作,将一段区间内的数加上c:2.查询操作,查询一段区间内的数的和. 思路: 线段树裸题,区间修改.区间查询,维护和以及加上的数,由于无序,不需要向下推标记, ...
- 【分块】【线段树】bzoj3212 Pku3468 A Simple Problem with Integers
线段树入门题…… 因为poj原来的代码莫名RE,所以丧病地写了区间修改的分块…… 其实就是块上打标记,没有上传下传之类. #include<cstdio> #include<cmat ...
- 3212: Pku3468 A Simple Problem with Integers
3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1053 So ...
- 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 ...
- bzoj 3212 Pku3468 A Simple Problem with Integers 线段树基本操作
Pku3468 A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2173 Solved: ...
- [BZOJ3212][POJ3468]A Simple Problem with Integers
题目大意: 维护一个长度为$n(n\leq100000)$的数列,支持区间加.区间求和两种操作,操作共$m(m\leq100000)$次. 思路: Splay区间操作. #include<cst ...
随机推荐
- Linux lsof命令 以及 恢复删除的文件
1.简介 lsof(list open files)是一个列出当前系统打开文件的工具.在linux环境下,任何事物都以文件的形式存在,通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件.所以如传 ...
- Shell文件权限和脚本执行
一.预备知识 1.shell的作用 2.常识 (1)Tab键自动补全 使用Terminal时,输入命令的前几个字母,敲tab会自动补全命令或文件名.目录等. 好处:操作速度更快:不容易出错: ...
- Hadoop 2.6.0+ZooKeeper+Hive HA高可用集群安装
http://blog.csdn.net/totxian/article/details/45248399
- css3的基本样式
一.css3字体(@font-face) 二.css3动画 三.css3多列 四.CSS3 outline-offset 属性 五.CSS3 resize 属性
- pathinfo()、dirname()、basename()获得文件的路径,名称等信息说明
在PHP中,若想通过函数获得一个文件的路径.名称,或者是扩展名等,是非常容易的一件事.可以使用dirname().basename().pathinfo()等多种途径获得相应的信息. 假设现在有一个图 ...
- Go - 数组 和 切片(array、slice)
一.数组 与其他大多数语言类似,Go语言的数组也是一个元素类型相同的定长的序列. (1)数组的创建 数组有 3 种创建方式: 1) [length]Type 2) [length]Type{value ...
- MySQL关键字
MySQL关键字 ADD ALL ALTER ANALYZE AND AS ASC ASENSITIVE BEFORE BETWEEN BIGINT BINARY BLOB BOTH BY CALL ...
- POJ 1860(spfa)
http://poj.org/problem?id=1860 题意:汇率转换,与之前的2240有点类似,不同的是那个题它去换钱的时候,是不需要手续费的,这个题是需要手续费的,这是个很大的不同. 思路: ...
- JVM内存管理------垃圾搜集器简介
引言 上一章我们已经探讨过GC的各个算法,那么垃圾搜集器是什么呢? 通俗的讲,使用编程语言将算法实现出来,产生的程序就是垃圾搜集器了.既然谈到了编程语言的实现,那么在讨论垃圾搜集器的时候,就已经涉及到 ...
- windows7 启用管理员账户
在虚拟机中安装了windows7,方便使用qq,使用百度云,office等常用的软件.虚拟机使用的oracle的VirtualBox,个人使用体验不错,最棒的功能是能将物理机中的磁盘映射到虚拟机中网络 ...