【分块】【线段树】bzoj3212 Pku3468 A Simple Problem with Integers
线段树入门题……
因为poj原来的代码莫名RE,所以丧病地写了区间修改的分块……
其实就是块上打标记,没有上传下传之类。
#include<cstdio>
#include<cmath>
using namespace std;
int n,m,a[],l[],r[],delta[],num[],sum,sz,x,y,v;
char op[];
long long sumv[];
void makeblock()
{
sz=sqrt(n);
for(sum=;sum*sz<n;sum++)
{
l[sum]=(sum-)*sz+;
r[sum]=sum*sz;
for(int i=l[sum];i<=r[sum];i++) {num[i]=sum; sumv[sum]+=a[i];}
}
l[sum]=sz*(sum-)+; r[sum]=n;
for(int i=l[sum];i<=r[sum];i++) {num[i]=sum; sumv[sum]+=a[i];}
}
inline void update()
{
if(num[x]+>=num[y]){for(int i=x;i<=y;i++) a[i]+=v;}
else
{
for(int i=x;i<=r[num[x]];i++) a[i]+=v;
for(int i=l[num[y]];i<=y;i++) a[i]+=v;
for(int i=num[x]+;i<num[y];i++) delta[i]+=v;
}
}
inline void query()
{
long long ans=;
if(num[x]+>=num[y]){for(int i=x;i<=y;i++) ans+=a[i];}
else
{
for(int i=x;i<=r[num[x]];i++) ans+=(long long)(delta[num[x]]+a[i]);
for(int i=l[num[y]];i<=y;i++) ans+=(long long)(delta[num[y]]+a[i]);
for(int i=num[x]+;i<num[y];i++) ans+=sumv[i]+(long long)((l[i]-r[i]+)*delta[i]);
}
printf("%lld\n",ans);
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=;i<=m;i++)
{
scanf("%s%d%d",op,&x,&y);
if(op[]=='Q') query();
else {scanf("%d",&v); update();}
}
return ;
}
【分块】【线段树】bzoj3212 Pku3468 A Simple Problem with Integers的更多相关文章
- 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 ...
- 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 ...
- 【成端更新线段树模板】POJ3468-A Simple Problem with Integers
http://poj.org/problem?id=3468 _(:зゝ∠)_我又活着回来啦,前段时间太忙了写的题没时间扔上来,以后再说. [问题描述] 成段加某一个值,然后询问区间和. [思路] 讲 ...
- bzoj3212 pku3468 A Simple Problem with Integers
一个有初值的数列.区间加.区间查 用线段树直接水过 然而并没有1A,主要是做题太快没看规模结果没注意线段树要用longlong建 卧槽怎么可以这么坑爹,害得我看见wa心慌了,还以为连线段树都要跪 一开 ...
- BZOJ3212 Pku3468 A Simple Problem with Integers 题解
题目大意: 一个数列,有两个操作:1.修改操作,将一段区间内的数加上c:2.查询操作,查询一段区间内的数的和. 思路: 线段树裸题,区间修改.区间查询,维护和以及加上的数,由于无序,不需要向下推标记, ...
- POJ 3468 (线段树 区间增减) A Simple Problem with Integers
这题WA了好久,一直以为是lld和I64d的问题,后来发现是自己的pushdown函数写错了,说到底还是因为自己对线段树理解得不好. 因为是懒惰标记,所以只有在区间分开的时候才会将标记往下传递.更新和 ...
- 线段树专题 POJ3468 A Simple Problem with Integers
题意:n个点.m个操作.两种操作类型.C X Y K 表示区间[x,y]上每一个点值加k.Q X Y 求区间[x,y]的和 分析:线段树区间求和,裸模板 注意:结果会超int,要用long long ...
- (线段树模板)A Simple Problem with Integers --POJ--3468
链接: http://poj.org/problem?id=3468 代码: #include<stdio.h> #include<algorithm> #include< ...
随机推荐
- 运动目标前景检测之ViBe源代码分析
一方面为了学习,一方面按照老师和项目的要求接触到了前景提取的相关知识,具体的方法有很多,帧差.背景减除(GMM.CodeBook. SOBS. SACON. VIBE. W4.多帧平均……).光流(稀 ...
- Patch Windows with SSM on AWS
ec2ssmupdate https://docs.amazonaws.cn/systems-manager/latest/userguide/systems-manager-patch.htmlht ...
- jw player笔记二----修改logo
一.修改HTML5模式下的logo 见http://blog.csdn.net/xiong_mao_1/article/details/17222757 二.修改FLASH模式下的logo IE7/8 ...
- 用eval转化对象
var str = '{"name": "tom","age": 12,"sex": "man"}' ...
- 【Foreign】Research Rover [DP]
Research Rover Time Limit: 25 Sec Memory Limit: 256 MB Description Input Output 仅一行一个整数表示答案. Sample ...
- bootstrap-datetimepicker年视图中endDate设置之后比正常时间提前两个月
问题 bootstrap-datetimepicker年视图中endDate设置结束时间为2016-08,(即8月之后的日期不能选)而在日历上显示时为2016-06,相差两个月,即6月之后的日期不能选 ...
- jetty bleed漏洞利用工具
两个exp: https://github.com/AppSecConsulting/Pentest-Tools/blob/master/jetty-bleed.py https://github.c ...
- python2.7字典转换成json时中文字符串变成unicode的问题:
参考:http://blog.csdn.net/u014431852/article/details/53058951 编码问题: python2.7字典转换成json时中文字符串变成unicode的 ...
- UVALIVE 3562 Remember the A La Mode!
费用流 建图很简单直接上代码 #include <map> #include <set> #include <list> #include <cmath> ...
- python基础===socket模块的讲解(转)
一.网络知识的一些介绍 socket 是网络连接端点.例如当你的Web浏览器请求www.jb51.net上的主页时,你的Web浏览器创建一个socket并命令它去连接 www.jb51.net的Web ...