题目链接

#include<cmath>
#include<cstdio>
#include<cctype>
#include<algorithm>
using namespace std;
const int N=1e5+5;
#define LL long long int n,belong[N],size;
LL A[N],sum[N],tag[N]; inline LL read()
{
LL now=0,f=1;register char c=getchar();
for(;!isdigit(c);c=getchar())
if(c=='-') f=-1;
for(;isdigit(c);now=now*10+c-'0',c=getchar());
return now*f;
} void Add(int l,int r,LL v)
{
for(int i=l;i<=min(r,belong[l]*size);++i)
A[i]+=v, sum[belong[i]]+=v;
if(belong[l]!=belong[r])
for(int i=(belong[r]-1)*size+1;i<=r;++i)
A[i]+=v, sum[belong[i]]+=v;
for(int i=belong[l]+1;i<belong[r];++i)
tag[i]+=v;
}
LL Query(int l,int r)
{
LL res=0;
for(int i=l;i<=min(r,belong[l]*size);++i)
res+=A[i]+tag[belong[i]];
if(belong[l]!=belong[r])
for(int i=(belong[r]-1)*size+1;i<=r;++i)
res+=A[i]+tag[belong[i]];
for(int i=belong[l]+1;i<belong[r];++i)
res+=sum[i]+tag[i]*size;
return res;
} int main()
{
freopen("shuliec.in","r",stdin);
freopen("shuliec.out","w",stdout); n=read();size=sqrt(n);
for(int i=1;i<=n;++i)
belong[i]=(i-1)/size+1, A[i]=read(), sum[belong[i]]+=A[i];
int m=read(),l,r;LL v;char opt[6];
while(m--)
{
scanf("%s",opt);l=read(),r=read();
if(opt[0]=='A')
v=read(), Add(l,r,v);
else
printf("%lld\n",Query(l,r));
} return 0;
}

COGS.1317.数列操作c(分块 区间加 区间求和)的更多相关文章

  1. cogs 1317. 数列操作C 区间修改 区间查询

    1317. 数列操作C ★★★   输入文件:shuliec.in   输出文件:shuliec.out   简单对比时间限制:1 s   内存限制:128 MB [题目描述] 假设有一个长度为 n( ...

  2. COGS 2638. 数列操作ψ 线段树

    传送门 : COGS 2638. 数列操作ψ 线段树 这道题让我们维护区间最大值,以及维护区间and,or一个数 我们考虑用线段树进行维护,这时候我们就要用到吉司机线段树啦 QAQ 由于发现若干次an ...

  3. [用CDQ分治解决区间加&区间求和]【习作】

    [前言] 作为一个什么数据结构都不会只会CDQ分治和分块的蒟蒻,面对区间加&区间求和这么难的问题,怎么可能会写线段树呢 于是,用CDQ分治解决区间加&区间求和这篇习作应运而生 [Par ...

  4. 「模板」 线段树——区间乘 && 区间加 && 区间求和

    「模板」 线段树--区间乘 && 区间加 && 区间求和 原来的代码太恶心了,重贴一遍. #include <cstdio> int n,m; long l ...

  5. cogs 1316. 数列操作B 区间修改 单点查询

    1316. 数列操作B ★★   输入文件:shulieb.in   输出文件:shulieb.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述] 假设有一个大小为 n(n ...

  6. cogs 264. 数列操作 单点修改 区间查询

    http://cogs.pro:8080/cogs/problem/problem.php?pid=pyNimmVeq 264. 数列操作 ★☆   输入文件:shulie.in   输出文件:shu ...

  7. 【BZOJ】1798: [Ahoi2009]Seq 维护序列seq 线段树多标记(区间加+区间乘)

    [题意]给定序列,支持区间加和区间乘,查询区间和取模.n<=10^5. [算法]线段树 [题解]线段树多重标记要考虑标记与标记之间的相互影响. 对于sum*b+a,+c直接加上即可. *c后就是 ...

  8. COGS.264.数列操作(分块 单点加 区间求和)

    题目链接 #include<cmath> #include<cstdio> #include<cctype> #include<algorithm> u ...

  9. COGS 264. 数列操作

    时间限制:1 s   内存限制:160 MB [问题描述] 假设有一列数 {Ai }(1 ≤ i ≤ n) ,支持如下两种操作: (1)将 A k 的值加 D .( k, D 是输入的数) (2) 输 ...

随机推荐

  1. python f-string

    文章目录 1. 主要内容 1.1. 旧时代的格式化字符串 1.1.1. Option #1: %-formatting 1.1.2. 怎样使用 %-formatting 1.1.3. 为什么 %-fo ...

  2. linux 定期清除日志

    clearLog.sh #!/bin/sh find /usr/local/apache/logs -mtime + 30 -name "*.log" -exec rm {} \; ...

  3. C#实现图片叠加,图片上嵌入文字,文字生成图片的方法

    /// <summary>     /// 图片叠加     /// </summary>     /// <param name="sender"& ...

  4. 016_nginx运维问题总结

    一.关于nginx请求包过大的解决思路 message-api.jyall.me.conf nginx报错问题问题定位,经分析跟接入navigator后关联不大,可参考一下结论连接超时抓包分析了一下每 ...

  5. centos7 Firewalld操作集合

    =============================================== 2019/4/15_第1次修改                       ccb_warlock == ...

  6. 火狐mozilla官方ftp站点获取旧版本火狐的下载地址

    http://ftp.mozilla.org/pub/firefox/releases/

  7. LeetCode(42):接雨水

    Hard! 题目描述: 给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水. 上面是由数组 [0,1,0,2,1,0,1,3,2,1,2,1] 表示的高度 ...

  8. wpf Assembly.LoadFile dll GetType 反射 抛异常 不具有由 URI 识别的资源。

    public static void LoadViewFromUri(this Window window, string baseUri) { try { var resourceLocater = ...

  9. PHP获取文件后缀名

    PHP获取文件后缀名是PHP学习者常见的一种操作,无论是在面试过程中还是PHP新手自学中.PHP获取文件后缀名都是很普遍的需要掌握的一个知识点. 下面我们就给大家总结介绍PHP获取文件扩展名也就是后缀 ...

  10. poj1470 LCA倍增法

    倍增法模板题 #include<iostream> #include<cstring> #include<cstdio> #include<queue> ...