poj3468 A Simple Problem with Integers 线段树区间更新

HAL库:中断处理函数 及 weak弱声明中断回调函数 详解 HAL库中断处理函数 及 weak弱声明中断回调函数 阅读详情

A Simple Problem with Integers

You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of numbers in a given interval.

Input

The first line contains two numbers N and Q. 1 ≤ N,Q ≤ 100000.
The second line contains N numbers, the initial values of A1, A2, ... , AN. -1000000000 ≤ Ai ≤ 1000000000.
Each of the next Q lines represents an operation.
"C a b c" means adding c to each of Aa, Aa+1, ... , Ab. -10000 ≤ c ≤ 10000.
"Q a b" means querying the sum of Aa, Aa+1, ... , Ab.

Output

You need to answer all Q commands in order. One answer in a line.

Sample Input

10 5
1 2 3 4 5 6 7 8 9 10
Q 4 4
Q 1 10
Q 2 4
C 3 6 3
Q 2 4

Sample Output

4
55
9
15

Hint

The sums may exceed the range of 32-bit integers.

思路:

一个线段树区间更新的板子题,lazy思想,具体不是太懂,就.........不写了

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn = (int)1e5 + 10;
int a[maxn];
struct node
{
    int left,right;
    ll vue,num;
}tree[maxn << 2];

void build(int l,int r,int o)
{
    tree[o].left = l,tree[o].right = r;
    tree[o].num = 0;
    if (l == r)
    {
        tree[o].vue = a[l];
        return ;
    }
    int mid = (l + r) >> 1;
    build(l,mid,o << 1);
    build(mid + 1,r,o << 1 | 1);
    tree[o].vue = tree[o << 1].vue + tree[o << 1 | 1].vue;
}
void update(int l,int r,ll x,int o)
{
    if (tree[o].left == l && tree[o].right == r)
    {
        tree[o].num += x;
        return ;
    }
    tree[o].vue += x * (r - l + 1);
    int mid = (tree[o].left + tree[o].right) >> 1;

    if (r <= mid) update(l,r,x,o << 1);
    else if (l > mid) update(l,r,x,o << 1 | 1);
    else
    {
        update(l,mid,x,o << 1);
        update(mid + 1,r,x,o << 1 | 1);
    }
}
ll query(int l,int r,int o)
{
    if (tree[o].left == l && tree[o].right == r)
        return tree[o].vue + (r - l + 1) * tree[o].num;
    int mid = (tree[o].left + tree[o].right) >> 1;
    tree[o].vue += tree[o].num * (tree[o].right - tree[o].left + 1);
    update(tree[o].left,mid,tree[o].num,o << 1);
    update(mid + 1,tree[o].right,tree[o].num,o << 1 | 1);
    tree[o].num = 0;
    if (r <= mid) return query(l,r,o << 1);
    else if (l > mid) return query(l,r,o << 1 | 1);
    else return query(l,mid,o << 1) + query(mid + 1,r,o << 1 | 1);
}
int main()
{
    int n,m;
    while (~scanf("%d %d",&n,&m))
    {
        int u,v,x;
        char q[3];
        for (int i = 1;i <= n;i ++)
            scanf("%d",&a[i]);
        build(1,n,1);
        while (m --)
        {
            scanf("%s",q);
            if (q[0] == 'Q')
            {
                scanf("%d %d",&u,&v);
                printf("%lld\n",query(u,v,1));
            }
            else
            {
                scanf("%d %d %d",&u,&v,&x);
                update(u,v,x,1);
            }
        }
    }
    return 0;
}

 

GameFramework 框架详解之 Network网络模块 工具链 GameFramework(下面简称GF)Demo中,已经给我们提供了Network模块使用的protobuf使用的动态链接库protobuf-net.dll,但是GF并没有给我们提供protobuf相关的工具链,比如:1.proto文件自动导出对应c#的Packet类和PacketHandler类2.导出Packet类继承IReference以便使用引用池。3.自动生成Packet类和PacketHandler的Id,且保持和服务器Id一一对应。 阅读详情

相关推荐

国产AI芯片实战:用寒武纪MLU370低成本部署DeepSeek-R1,实测推理效果与成本分析

本文详细介绍了寒武纪MLU370芯片在部署DeepSeek-R1大模型时的实战效果与成本优势。通过实测数据对比,MLU370在推理速度、能效比和本地化服务方面表现突出,尤其适合智能客服、内容生成等场景,可显著降低硬件投入和运维成本。

weixin_30613727的博客 461

POJ 3468 A Simple Problem with Integers【线段树区间更新入门题】

线段树区间更新入门题。区间更新用单点更新的方法去做必然会TLE,当要更新的区间正好是某个节点的区间的时候,我们就更新到此,不再继续往下更新,从而节省了时间,实现了次区间更新的高效性。 但后面更新的区间是上次更新区间的子区间的时候就要把之前保存在父节点的更新数据“下放”到对应的子区间,从而实现了操作的正确性。 对于线段树区间更新的描述网上有好多不错的博客,我就不用再去造轮子了。写法也有好多种,适合自己的才是最好的。 以下三篇代表了几种不同的写法。 此题参考博客:http://blog.csdn.net/w00

AC_Dreameng 1420

AI漫剧制作全流程零基础实操指南:从剧本到剪辑

AI漫剧是一种利用AI工具将剧本、分镜、出图、配音、剪辑整合为流水线的短视频内容形式。其技术原理基于文生图、图生图与文本转语音模型的组合,核心挑战在于角色一致性控制与分镜批量出图。这项技术大幅降低了视频制作门槛,使个人创作者无需演员和设备即可产出剧情向短内容,广泛应用于短视频平台的情景剧、玄幻、甜宠等题材。本文给出了一套零基础可照做的全流程实操方案,覆盖剧本提示词、分镜表、出图选型、配音合成与剪辑模板,帮助你快速跑通AI漫剧制作链路。

weixin_29048309的博客 571

POJ 3468 A Simple Problem with Integers(线段树区间更新)

题目来源:http://poj.org/problem?id=3468 问题描述 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 142569   Accepted: 44...

da_kao_la的博客 274

人大金仓集群部署(主备)

4.2 上传安装包镜像和授权文件到install目录下并授权。1、复制系统脚本到/opt/kingbase目录下(主节点)4.2 修改cluster_install.sh。回车进行下一步,直到出现以下界面,回复Y键回车。三、安装kingbase客户端段(都要安装)install目录作为安装包具体存放目录。4.1 修改install.conf文件。2、复制授权文件到安装目录下(主节点)3、修改ssh参数(节点都要配置)5、安装kingbase客户端。二、基本环境配置(都要配置)6、数据库集群安装(主节点)

edutech_wang的博客 2003

手机拍照对焦快准狠的秘密:一文看懂PDAF、Dual Pixel和Super PD的区别

本文深入解析手机拍照中的三种主流相位检测自动对焦(PDAF)技术:Shield Pixel、Super PD和Dual Pixel。通过对比它们的原理、优缺点及实际表现,帮助读者理解不同技术的对焦速度、暗光表现和画质影响,从而做出更明智的购机选择。

weixin_26985923的博客 496

【POJ】3468 - A Simple Problem with Integers(线段树区间更新)

题目链接:点击打开链接 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 100877   Accepted: 31450 Case Time Limit: 2000MS Descrip

wyg1997 2319

UHPC的疲劳计算——兼论ModelCode2010的适用性

ModelCode2010的混凝土疲劳计算方法是适用于UHPC的。

George的博客 1332

POJ[3468] A Simple Problem with Integers 【线段树区间更新】

Description You haveNintegers,A1,A2, ... ,AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is t...

醉酒、冰城外 159

ENVI遥感数字图像处理方法(一)

文章目录1.查看图像的空间分布特征(一)生成灰度图像(二)生成假彩色图像(三)连接不同视图的影像2.查看图像的像元灰度值3.统计并查看图像直方图 1.查看图像的空间分布特征 在打开一幅遥感影像时,有两个文件,我们要选择数据文件来打开。 打开过后,点击Data Manager,查看该影像的波段 该影像共有6个波段 (一)生成灰度图像 步骤如下: (二)生成假彩色图像 先生成一个一般的假彩色图像: 再生成一个标准假彩色图像,将其存放在一个新的视图中: 标准假彩色图像波段构成为:近红外、红光波段、绿

江昊东的博客 5万+

HyperLynx(二)LineSim的基本操作

如果是仿真眼图,那么还有一个眼图模板(EyeMask)加载选项,这些选项必须经过勾选之后才会在显示界面中显示,以使相关的信息在波形显示的界面呈现,如图所示。另一种为振荡器激励,即连续的脉冲激励源,在这个选项中有两个参数需要设置,即激励源的频率(MHz)和占空比(Duty),如图所示。如果Pins一栏中有多个引脚具有相同的模型,那么可以选中已经赋值模型的引脚,单击右下角的Copy按钮进行复制,然后再选择同类型并没有赋模型的引脚,单击粘贴或者全部粘贴,即完成模型赋值,但是不同类型的模型就不能这样操作。...

小幽余生不加糖 6119

poj3468 A Simple Problem with Integers 线段树【区间更新】

题目链接在这里 题目描述: 有n个数m个操作,操作有两种: 1.Q x y 查询区间[x, y]的和 2.C x y z 区间[x, y]中的每个元素增加z 思路分析: 运用线段树维护点的信息,在区间更新的时候lazy思想在节点上mark一下。 代码如下: #include &lt;cstdio&gt; #include &lt;cstring&gt; #include &lt;...

Joel 240

黑猫带你学eMMC协议第14篇:eMMC FFU详解(Field Firmware Update)

1 前言 1.1 声明 本文依据eMMC JEDEC5.1及个人工作经验整理而成,如有错误请留言。 本文结合eMMC JEDEC5.1协议手册查看效果更佳。 1.2 内容提要 1、ffu相关寄存器有哪些? 2、如何设置ffu? 3、什么是ffu?是否能够更新旧版本的固件到emmc? 4、ffu配置流程图。 2 什么是FFU 主机下载新的固件到eMMC,下载成功后eMMC将固件安装到设备。 3 相关寄存器/命令 SUPPORTED_MODES [493] FFU_FEATURES [492] 该

黑猫奥利奥的博客 4674

POJ3468 A Simple Problem with Integers 线段树区间更新

POJ3468 A Simple Problem with Integers/*线段树区间更新 2000MS 4484K */ #include &lt;stdio.h&gt; #include &lt;string.h&gt; const int MAX=1e5+5; long long tree[MAX*4]; long long lazy[MAX*4];//延时数组 void read...

Qianyri的博客 247

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

Poj3468 A Simple Problem with Integers 线段树、区间更新

Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is

Megumin的博客 353

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

poj 3468 A Simple Problem with Integers 线段树 区间更新求和

线段树第二天,下午由于做了多校的第一场virtual judge,所以直到晚上才有时间来搞这道题 除了早上做的那个区间染色的问题,这个问题应该也是个入门题,当然由于鄙人智商是硬伤,没太反应明白,查了解题报告,再加上自己的一些尝试,最终侥幸AC了,下面说说思路: 首先,更新区间的时候不可能更新区间里的每一个点,这样复杂度太高 因此,在update的时候,找到对应的区间之后,直接给该区间存储一个

renew 746

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

POJ3468 A Simple Problem with Integers 线段树区间更新

A Simple Problem with Integers  线段树区间更新 You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number i

资深罚时选手 232

poj3468 A Simple Problem with Integers 线段树区间更新,区间求和

传送门:poj3468 A Simple Problem with Integers题目大意输入:第一行输入两个数N和Q。N代表有多少个元素,Q代表进行多少次操作 第二行数输入n个数 表示对应的初始值 然后下面的Q行代表操作: C a b c把a到b区间的数增加c Q a b输出a到b区间的数量之和 输出:每当有Q操作输出a到b区间的数量之和解题思路如果总是WA的话,可以测试这个数据:10

woshinannan的专栏 601

A Simple Problem with Integers(POJ-3468)线段树 区间更新+区间求和

ASimple Problem with Integers(POJ-3468)线段树 区间更新加区间求和题目大意 POJ-3468的原题链接 题目大意 有一个数组长度为N的数组,总共输入T组数据指令,当输入 Q 指令时,代表要将 下标在 a,b之间的元素求和,而当输入C指令时,要求要将下标在a,b之间的所有数组元素都加上c. #include <cstring> #include &l...

一只特立独行的猫的博客 228

poj 3468 A Simple Problem with Integers 线段树区间更新

点击打开链接题目链接 A Simple Problem with Integers Time Limit:5000MS Memory Limit:131072K Total Submissions:63565 Accepted:19546 Case Time Limit:2000MS ...

aodiyi6351的博客 139

poj 3468 A Simple Problem with Integers(线段树区间更新)

题意:http://poj.org/problem?id=3468 这纯粹研究区间更新,区间查询,熟练掌握线段树的运用技能。相比,单点更新,多了add标志,adding, query操作时也多了对它的特殊操作pushdown。 #include #include using namespace std; #define LL long long const LL maxn=1e5+5;

theArcticOcean 689

线段树 区间更新 区间查询 poj3468 A Simple Problem with Integers

相比较于单点更新和单点查询来说 区间更新多了一个pushdown函数 代码如下void pushdown(int root,int m){ if(add[root]){ add[root<<1] += add[root]; add[root<<1 | 1] += add[root]; sum[root>1)); sum[root>1); add[root] = 0; }

meixiuxiudd的博客 432

POJ 3468 A Simple Problem with Integers(线段树区间更新+求和)

题目链接:http://poj.org/problem?id=3468 参考了胡浩大牛的代码模板: 区间更新+区间求和 #include #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define mid (l+r)>>1 #define LL long long using namespace std; const int ma

Learn as if you were to live forever 567

POJ 3468:A Simple Problem with Integers(线段树应用之:区间更新,区间查询)

POJ 3468:A Simple Problem with Integers(线段树应用之:区间更新,区间查询) Description You have N integers, A1, A2, … , AN. You need to deal with two kinds of operations. One type of operation is to add some given n...

serendipity的博客 371

POJ-3468 A Simple Problem with Integers 【线段树:区间更新】

POJ-3468 A Simple Problem with Integers 【线段树:区间更新】 题意:对于一串n长的数,进行m次操作,具体如下: 两种操作: 'Q’:询问 [ a,b ]区间的和值 'C’:[ a,b ]区间里面的每个数+x

SaySomething 325

POJ 3468 A Simple Problem with Integers (线段树区间更新)

题目链接: 戳我 题目大意: 一组数,从 1 到 n,有两个操作, Q a b -->询问 a 到 b的这个区间的和 C a b c  --->让a 到 b这个区间的每个数都加上 c 样例解释: 略 解题思路: 自然线段树区间更新了。今天复习一下区间更新。。。 //Author LJH //www.cnblogs.com/tenlee #inclu...

aocang4831的博客 149
上一篇: hdu1166 敌兵布阵 线段树
下一篇: HPU暑期集训积分赛3
cloudy_happy
博客等级 码龄9年 35粉丝 203原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值