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 两个操作,区间增加 ...
随机推荐
- Android自定义View学习笔记(一)
绘制基础 参考:HenCoder Android 开发进阶: 自定义 View 1-1 绘制基础 Paint详解 参考:HenCoder Android 开发进阶: 自定义 View 1-2 Pain ...
- python第三方库自动安装脚本
#python第三方库自动安装脚本,需要在cmd中运行此脚本#BatchInstall.pyimport oslibs = {"numpy","matplotlib&qu ...
- scrapy中deferred的回调
def _next_request_from_scheduler(self, spider):#在引擎中处理一个请求 slot = self.slot request = slot.scheduler ...
- Mysqli 数据库连接类
<?php namespace Lib; // 数据库连接类 class DB { //私有的属性 private static $dbcon = false; private $host; p ...
- delphi 第三方组件 log4cpp.dll
log4cpp.dll LogHelper.dll TcxGridSite TcxSpreadSheetBook TcxSpreadSheetBook TcxTreeList TcxButtonEdi ...
- Spring boot 自定义starter
以下配置来自尚硅谷.. 常用如何配置 @Configuration //指定这个类是一个配置类 @ConditionalOnXXX //在指定条件成立的情况下自动配置类生效 @AutoConfigur ...
- OC代码编译成c++代码 编译器命令
xcrun -sdk iphoneos clang -arch x86_64 -rewrite-objc Person+Test.m clang -rewrite-objc -fobjc-arc -s ...
- vue:页面跳转和传参(页面之间,父传子,子传父)
1.返回上一个页面: A.<a @click="$router.back(-1)" class="btn">重新加载</a> B.thi ...
- 尚硅谷redis学习2-redis的安装和HelloWorld
Reids: remote dictionary server redis特点:支持持久化,支持复杂数据类型,支持备份 下载: 解压: 执行make, make install 可能会需要安装make ...
- U3D GPU蒙皮
在U3D中默认情况下是使用CPU蒙皮的,在BUILDING SETTING中的others中可以设置为GPU skinning