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 ...
随机推荐
- webpack解惑:require的五种用法 (转)
我之前在 <前端搭环境之从入门到放弃>这篇文章中吐槽过,webpack中可以写commonjs格式的require同步语法,可以写AMD格式的require回调语法,还有一个require ...
- C# Process.Start()方法详解
System.Diagnostics.Process.Start(); 能做什么呢?它主要有以下几个功能: 1.打开某个链接网址(弹窗). 2.定位打开某个文件目录. 3.打开系统特殊文件夹,如“控制 ...
- [转] Unity Mathf 数学运算(C#)
Mathf.Abs 绝对值 计算并返回指定参数 f 绝对值. Mathf.Acos 反余弦 static function Acos (f : float) : float 以弧度为单位计算并返回参数 ...
- C语言基础(1)-基本语法及注意事项
1. include 头文件包含 #include <stdio.h>这个是hello world程序的第一句话 # 代表预编译指令 #include的意思就是头文件包含,使用C语言库函数 ...
- Unity3D 之脚本架构,优雅地管理你的代码
本文参考雨松MOMO大神的帖子: 图片全部来自他的帖子(请允许我偷懒下) --------------------------------------------------------------- ...
- pyquery的问题
在使用pyquery时发现一些问题, 1.爬取的html中如果有较多的错误时,不能很好的补全. 2.如果要获取某个class中的内容时,如果内容太多不能取完整!只能取一部分. 这个在现在的最新版本中还 ...
- [Hadoop] 在Ubuntu系统上一步步搭建Hadoop(单机模式)
1 Hadoop的三种创建模式 单机模式操作是Hadoop的默认操作模式,当首次解压Hadoop的源码包时,Hadoop无法了解硬件安装环境,会保守地选择最小配置,即单机模式.该模式主要用于开发调试M ...
- struts2 用if标签判断字符串包含
String testStr = "用来判断是否包含的字符串"; <s:property value="testStr"/> <s:if te ...
- C# 构建XML(简单示例)
C# 构建XML的简单示例: var pars = new Dictionary<string, string> { {"url","https://www. ...
- rabbitmq 的心跳机制&应用
官方文档说: If a consumer dies (its channel is closed, connection is closed, or TCP connection is lost) w ...