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 两个操作,区间增加 ...
随机推荐
- hasattr getattr setattr delattr --> (反射)
class Room: def __init__(self,name): self.name = name def big_room(self): print('bigroot') R = Room( ...
- react-navigation,StackNavigator,TabNavigator 导航使用
StackNavigator 参考这里 TabNavigator 参考这里 是一个组合,我把这2个写在一起了 代码: import React, { Component } from 'react ...
- Linux服务器mysql,nginx等自动停止的排查,以及解决方法
最近发现自己使用的某台云服务武器只要稍微流量大一点,就会出现莫名的的数据库连接错误的情况 ,然后连上服务器查看,发现mysql进程被结束了,经常出现这种情况,这还怎么得了,然后第一时间查看mysql日 ...
- 【358】GitHub 上面文件夹下载方法
参考:https://www.bilibili.com/read/cv210500/ 参考:https://www.jianshu.com/p/743ecc20ffb2 软件下载:Downloads ...
- Apache Mina UDP连接目标服务器地址时出现异常
俩种情形,第一种是开始连接时候就没连上服务器:第二种是服务器关闭连接,出现的异常: 第一种: java.lang.reflect.InvocationTargetException at sun.re ...
- Class-reference types 类引用类型--快要失传的技术
先摘一段原版的说明: A class-reference type, sometimes called a metaclass, is denoted by a construction of the ...
- Python类的进阶.md
属性绑定 在python中可以给类对象动态的绑定属性 但是由于这种特性,随意动态绑定也会带来麻烦,因此可用__slots__来限制可绑定的属性名称 __slots__的绑定对于子类是不生效的,只对当前 ...
- 我理解的BFC(块级格式化上下文)
BFC(Block formatting context) 直译为"块级格式化上下文". BFC它是一个独立的渲染区域,只有Block-level box参与, 它规定了内部的Bl ...
- k近邻算法(KNN)
k近邻算法(KNN) 定义:如果一个样本在特征空间中的k个最相似(即特征空间中最邻近)的样本中的大多数属于某一个类别,则该样本也属于这个类别. from sklearn.model_selection ...
- spark LBFGS 设置参数
http://blog.csdn.net/bon_mot/article/details/72461318