题目链接: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的更多相关文章

  1. LibreOJ 6280 数列分块入门 4(分块区间加区间求和)

    题解:分块的区间求和比起线段树来说实在是太好写了(当然,复杂度也高)但这也是没办法的事情嘛.总之50000的数据跑了75ms左右还是挺优越的. 比起单点询问来说,区间询问和也没有复杂多少,多开一个su ...

  2. LOJ #6280. 数列分块入门 4-分块(区间加法、区间求和)

    #6280. 数列分块入门 4 内存限制:256 MiB时间限制:500 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: hzwer 提交提交记录统计测试数据讨论   题目描述 给出一个 ...

  3. LibreOJ 6277. 数列分块入门 1 题解

    题目链接:https://loj.ac/problem/6277 题目描述 给出一个长为 \(n\) 的数列,以及 \(n\) 个操作,操作涉及区间加法,单点查值. 输入格式 第一行输入一个数字 \( ...

  4. LibreOJ 6277 数列分块入门 1(分块)

    题解:感谢hzwer学长和loj让本蒟蒻能够找到如此合适的入门题做. 这是一道非常标准的分块模板题,本来用打标记的线段树不知道要写多少行,但是分块只有这么几行,极其高妙. 代码如下: #include ...

  5. LibreOJ 6278. 数列分块入门 2 题解

    题目链接:https://loj.ac/problem/6278 题目描述 给出一个长为 \(n\) 的数列,以及 \(n\) 个操作,操作涉及区间加法,询问区间内小于某个值 \(x\) 的元素个数. ...

  6. LibreOJ 6285. 数列分块入门 9

    题目链接:https://loj.ac/problem/6285 其实一看到是离线,我就想用莫队算法来做,对所有询问进行分块,但是左右边界移动的时候,不会同时更新数字最多的数,只是后面线性的扫了一遍, ...

  7. LibreOJ 6282. 数列分块入门 6

    题目链接:https://loj.ac/problem/6282 参考博客:http://www.cnblogs.com/stxy-ferryman/p/8560551.html 这里如果用数组的话元 ...

  8. LibreOJ 6277. 数列分块入门 2

    题目链接:https://loj.ac/problem/6278 参考博客:https://blog.csdn.net/qq_36038511/article/details/79725027 这题我 ...

  9. LibreOJ 6277. 数列分块入门 1

    题目链接:https://loj.ac/problem/6277 参考博客:https://www.cnblogs.com/stxy-ferryman/p/8547731.html 两个操作,区间增加 ...

随机推荐

  1. MBR (主引导记录)

    概念 主引导记录(MBR,Main Boot Record)是位于磁盘最前边的一段引导(Loader)代码.它负责磁盘操作系统(DOS)对磁盘进行读写时分区合法性的判别.分区引导信息的定位,它由磁盘操 ...

  2. Linux sed 流编辑器

    sed是stream editor的简称,也就是流编辑器.盗用一张图片解释原理 命令格式: SYNPPSIS: sed [OPTION]… {script-only-if-no-other-scrip ...

  3. [转] golang socket

    server.go package main import ( "net" "fmt" "io/ioutil" "time&quo ...

  4. django 认证模块auth,表单组件form

    django认证系统(auth): 1.首先我们在新窗口中打开一个django项目,之后点击,

  5. air 调用jsfl 执行对应函数,并传参

    jsflPath = "WindowSWF/dt_tool_jsfl/" + event.item.fileName+".jsfl"; var element_ ...

  6. APP-9-文字识别-车牌识别

    1.获取Access Token APP-9.1-百度应用-文字识别 2.代码部分 <!DOCTYPE html> <html> <head> <meta c ...

  7. c++复习:STL之理论基础

    1 STL(标准模板库)理论基础 1.1基本概念 STL(Standard Template Library,标准模板库)是惠普实验室开发的一系列软件的统称.现然主要出现在C++中,但在被引入C++之 ...

  8. Pronunciation Guide for 25 Common Fruits

    Pronunciation Guide for 25 Common Fruits Share Tweet Share Tagged With: Vocabulary Words Know how to ...

  9. 使用adb查看CPU和内存

    adb shell ->cat/sys/class/net/wlan0/address 获取Mac地址 abd shell –>cat /proc/cpuinfo 获取CPU信息 adb ...

  10. Matlab实现BP网络识别字母

    训练样本空间   每个样本使用5×5的二值矩阵表征一个字母.一共10个字母类型,分别是N,I,L,H,T,C,E,F,Z,V.每个字母9个样本.共90个. N1=[1,0,0,0,1; 1,0,0,0 ...