LibreOJ 6280 . 数列分块入门 4
题目链接:https://loj.ac/problem/6280
加一个数组保存块的和。
代码:
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<vector>
#include<set>
#include<cstdio>
#include<string>
#include<deque>
using namespace std;
typedef long long LL;
#define eps 1e-8
#define INF 0x3f3f3f3f
#define maxn 50010
/*struct point{
int u,w;
};
bool operator <(const point &s1,const point &s2)
{
if(s1.w!=s2.w)
return s1.w>s2.w;
else
return s1.u>s2.u;
}*/
LL n,m,k,t,block;
LL a[maxn],sum[maxn],tag[maxn];
int lump[maxn];
void add(LL l,LL r,LL w)
{
for(int i=l;i<=min(lump[l]*block,r);i++)//这里错了n次...这里是r表示n,是为了防止l和r在一个块里面的情况,要引以为戒
{
a[i]+=w;
sum[lump[l]]+=w;
}
if(lump[l]!=lump[r])
{
for(int i=(lump[r]-)*block+;i<=r;i++)
{
a[i]+=w;
sum[lump[r]]+=w;
}
}
for(int i=lump[l]+;i<=lump[r]-;i++)
{
tag[i]+=w;
sum[i]+=w*block;
}
}
LL get_sum(LL l,LL r)
{
LL ans=;
for(int i=l;i<=min(lump[l]*block,r);i++)
ans+=a[i]+tag[lump[l]];
if(lump[l]!=lump[r])
{
for(int i=block*(lump[r]-)+;i<=r;i++)
ans+=a[i]+tag[lump[r]];
}
for(int i=lump[l]+;i<=lump[r]-;i++)
ans+=sum[i];
return ans;
}
int main()
{
scanf("%lld",&n);
block=sqrt(n);
fill(sum,sum+maxn-,);
fill(tag,tag+maxn-,);
for(int i=;i<=n;i++)
{
scanf("%lld",&a[i]);
lump[i]=(i-)/block+;
sum[lump[i]]+=a[i];
}
for(int i=;i<=n;i++)
{
LL op,l,r,w;
scanf("%lld%lld%lld%lld",&op,&l,&r,&w);
if(op==)
add(l,r,w);
else
printf("%lld\n",get_sum(l,r)%(w+));
}
return ;
}
LibreOJ 6280 . 数列分块入门 4的更多相关文章
- LibreOJ 6280 数列分块入门 4(分块区间加区间求和)
题解:分块的区间求和比起线段树来说实在是太好写了(当然,复杂度也高)但这也是没办法的事情嘛.总之50000的数据跑了75ms左右还是挺优越的. 比起单点询问来说,区间询问和也没有复杂多少,多开一个su ...
- LOJ #6280. 数列分块入门 4-分块(区间加法、区间求和)
#6280. 数列分块入门 4 内存限制:256 MiB时间限制:500 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: hzwer 提交提交记录统计测试数据讨论 题目描述 给出一个 ...
- LibreOJ 6277. 数列分块入门 1 题解
题目链接:https://loj.ac/problem/6277 题目描述 给出一个长为 \(n\) 的数列,以及 \(n\) 个操作,操作涉及区间加法,单点查值. 输入格式 第一行输入一个数字 \( ...
- LibreOJ 6277 数列分块入门 1(分块)
题解:感谢hzwer学长和loj让本蒟蒻能够找到如此合适的入门题做. 这是一道非常标准的分块模板题,本来用打标记的线段树不知道要写多少行,但是分块只有这么几行,极其高妙. 代码如下: #include ...
- LibreOJ 6278. 数列分块入门 2 题解
题目链接:https://loj.ac/problem/6278 题目描述 给出一个长为 \(n\) 的数列,以及 \(n\) 个操作,操作涉及区间加法,询问区间内小于某个值 \(x\) 的元素个数. ...
- LibreOJ 6285. 数列分块入门 9
题目链接:https://loj.ac/problem/6285 其实一看到是离线,我就想用莫队算法来做,对所有询问进行分块,但是左右边界移动的时候,不会同时更新数字最多的数,只是后面线性的扫了一遍, ...
- LibreOJ 6282. 数列分块入门 6
题目链接:https://loj.ac/problem/6282 参考博客:http://www.cnblogs.com/stxy-ferryman/p/8560551.html 这里如果用数组的话元 ...
- LibreOJ 6277. 数列分块入门 2
题目链接:https://loj.ac/problem/6278 参考博客:https://blog.csdn.net/qq_36038511/article/details/79725027 这题我 ...
- LibreOJ 6277. 数列分块入门 1
题目链接:https://loj.ac/problem/6277 参考博客:https://www.cnblogs.com/stxy-ferryman/p/8547731.html 两个操作,区间增加 ...
随机推荐
- ASP.NET Core MVC 概述
https://docs.microsoft.com/zh-cn/aspnet/core/mvc/overview?view=aspnetcore-2.2 ASP.NET Core MVC 概述 20 ...
- MongoDB 全部笔记
1. MongoDB: 是NOSQL的一种, 特长是分布式用的,用于处理爬虫数据 2. mongoDB 与 redis mongoDB是最像关系型的非关系型数据,更加适用于大数据,redis则更倾向于 ...
- js把mysql传过来的时间格式化为:0000-00-00 00:00:00
mysql传到前端的默认时间:2018-01-06T17:32:23+08:00 格式化的js代码 var time = '2018-01-06T17:32:23+08:00' var span = ...
- E2040 Declaration terminated incorrectly - System.ZLib.hpp(310) ZLIB_VERSION
[bcc32 Error] System.ZLib.hpp(310): E2040 Declaration terminated incorrectly Full parser context ...
- 深度学习原理与框架-Tensorflow基本操作-mnist数据集的逻辑回归 1.tf.matmul(点乘操作) 2.tf.equal(对应位置是否相等) 3.tf.cast(将布尔类型转换为数值类型) 4.tf.argmax(返回最大值的索引) 5.tf.nn.softmax(计算softmax概率值) 6.tf.train.GradientDescentOptimizer(损失值梯度下降器)
1. tf.matmul(X, w) # 进行点乘操作 参数说明:X,w都表示输入的数据, 2.tf.equal(x, y) # 比较两个数据对应位置的数是否相等,返回值为True,或者False 参 ...
- 机器学习进阶-图像金字塔与轮廓检测-模板匹配(单目标匹配和多目标匹配)1.cv2.matchTemplate(进行模板匹配) 2.cv2.minMaxLoc(找出矩阵最大值和最小值的位置(x,y)) 3.cv2.rectangle(在图像上画矩形)
1. cv2.matchTemplate(src, template, method) # 用于进行模板匹配 参数说明: src目标图像, template模板,method使用什么指标做模板的匹配 ...
- day02-格式化输出
python格式化字符串有%和{}两种 字符串格式控制符. 字符串输入数据格式类型(%格式操作符号) %%百分号标记%c字符及其ASCII码%s字符串%d有符号整数(十进制)%u无符号整数(十进制)% ...
- SAFESEH 映像是不安全的
1.打开该项目的“属性页”对话框 2.然后单击“链接器”--“命令行”,出现如下界面 3.将 /SAFESEH:NO 复制到“其它选项(D)”框中,然后点击应用 返回VS2013,重新编译运行程序即可 ...
- 解决 'Could not convert variant of type (NULL) into type (String)
写存储过程中有不允许为空的字段,在客户端转化取数时显示 Could not convert variant of type (NULL) into type (String) 可以在存储过程中使用is ...
- tar 打包当前目录下文件但不包括该录
今天想打包一些文件,但是不想把该目录打包进去 比如我想把test目录下文件打个包,安装正常的命令来 tar zcf test.tar.gz test 这样肯定会把test目录也打进去,解压后肯定是te ...