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

用线段树直接水过

然而并没有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. javascript数据结构与算法--基本排序算法分析

    javascript中的基本排序算法 对计算机中存储的数据执行的两种最常见操作是排序和检索,排序和检索算法对于前端开发尤其重要,对此我会对这两种算法做深入的研究,而不会和书上一样只是会贴代码而已,下面 ...

  2. 兼容IE6的min-width、min-height

    如果一个站是宽屏的,你左右拖动浏览器的窗口网站宽度会随着窗口的大小而改变,而浏览器窗口宽度减小到一定程度后就会出现下边的滚动条,网站宽度就不会再减小了,我们知道这一简单的功能用css的min-widt ...

  3. Node.js Stream-进阶篇

    作者:美团点评技术团队链接:https://zhuanlan.zhihu.com/p/21681115来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 上篇(基础篇)主要 ...

  4. JSP分页显示

    首先要定义四个变量: int pageSize: //每页显示多少条记录 int pageNow: //希望显示第几页 int pageCount: //一共有多少页 int rowCount: // ...

  5. linux source

    清华TUNA镜像源https://mirrors.tuna.tsinghua.edu.cn/ 中科大USTC镜像源 https://mirrors.ustc.edu.cn/ ali http://mi ...

  6. sql 获取一批指定范围且不重复的随机数

    declare @M int,@N int set @m=10 set @n=1 select top 10 cast(rand(checksum(newid()))*(@M-@N)+@n as in ...

  7. TypeError: test() got multiple values for keyword argument 'key'

    原因是: 1.函数调用的最终形式只会调用两个函数.一个list参数和一个dict参数,格式为call(func, list, dict); 2.如果传入参数中有key参数,那么首先key参数(包括扩展 ...

  8. [BZOJ2761][JLOI2011]不重复数字

    [BZOJ2761][JLOI2011]不重复数字 试题描述 给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复 ...

  9. Reverse Integer

    Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 public cl ...

  10. (iOS逆向工程)class-dump 安装与使用

    class-dump,是可以把OC运行时的声明的信息导出来的工具.说白了,就是可以导出.h文件.用class-dump可以把未经加密的app的头文件导出来.废话不多说.class-dump的下载地址是 ...