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

dell r630 配置raid_DELL服务器RAID配置图文教程 名称解释:Disk Group:磁盘组,这里相当于是阵列,例如配置了一个RAID5,就是一个磁盘组VD(Virtual Disk): 虚拟磁盘,虚拟磁盘可以不使用阵列的全部容量,也就是说一个磁盘组可以分为多个VDPD(Physical Disk): 物理磁盘HS:Hot Spare 热备Mgmt:管理【一】创建逻辑磁盘1、按照屏幕下方的虚拟磁盘管理器提示,在VD Mgmt菜单(可以通过CTRL+P... 阅读详情

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 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.

Source


经典的线段树题,在节点中增加一个add变量,记录该区间内所有点都增加的值,即可做到在O( log n ) 内做到区间更新。


#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
#define INF 0x3f3f3f3f
#define LL __int64
LL v;
int a,b;
struct node{
    int l,r;
    LL sum,add;
    int mid(){
        return (l+r)/2;
    }
};
node tree[400005];
void buildtree(int root,int l,int r)
{
    tree[root].l=l;
    tree[root].r=r;
    tree[root].sum=tree[root].add=0;
    if(l!=r){
        buildtree(2*root+1,l,(l+r)/2);
        buildtree(2*root+2,(l+r)/2+1,r);
    }
}
void vinsert(int root,int i,LL v)
{
    if(tree[root].l==tree[root].r){
        tree[root].sum=v;
        return;
    }
    tree[root].sum+=v;
    if(i<=tree[root].mid()){
        vinsert(2*root+1,i,v);
    }else{
        vinsert(2*root+2,i,v);
    }
}
void update(int root,int a,int b,LL v)
{
    if(tree[root].l==a&&tree[root].r==b){
        tree[root].add+=v;
        return;
    }
    tree[root].sum+=v*(b-a+1);
    if(b<=tree[root].mid()){
        update(2*root+1,a,b,v);
    }else if(a>tree[root].mid()){
        update(2*root+2,a,b,v);
    }else{
        update(2*root+1,a,tree[root].mid(),v);
        update(2*root+2,tree[root].mid()+1,b,v);
    }
}
LL answersearch(int root,int a,int b)
{
    LL answer=0;
    if(tree[root].l==a&&tree[root].r==b){
        return tree[root].sum+tree[root].add*(b-a+1);
    }
    tree[root].sum+=tree[root].add*(tree[root].r-tree[root].l+1);
    update(2*root+1,tree[root].l,tree[root].mid(),tree[root].add);
    update(2*root+2,tree[root].mid()+1,tree[root].r,tree[root].add);
    tree[root].add=0;
    if(b<=tree[root].mid()){
        return answersearch(2*root+1,a,b);
    }else if(a>tree[root].mid()){
        return answersearch(2*root+2,a,b);
    }else{
        return answersearch(2*root+1,a,tree[root].mid())+
        answersearch(2*root+2,tree[root].mid()+1,b);
    }
    return answer;
}
int main()
{
    int n,m;
    char ch;
    while(~scanf("%d%d",&n,&m)){
        buildtree(0,1,n);
        for(int i=1;i<=n;i++){
            scanf("%I64d",&v);
            vinsert(0,i,v);
        }
        while(m--){
            getchar();
            scanf("%c",&ch);
            if(ch=='C'){
                scanf("%d%d%I64d",&a,&b,&v);
                update(0,a,b,v);
            }else{
                scanf("%d%d",&a,&b);
                printf("%I64d\n",answersearch(0,a,b));
            }
        }
    }
    return 0;
}


论文阅读:Universal and Transferable Adversarial Attacks on Aligned Language Models. LLM Attacks 因为“即开即用”的大型语言模型能够生成大量令人反感的内容,近期的工作集中在对这些模型进行对齐,以防止不受欢迎的生成。尽管在规避这些措施方面取得了一些成功——即所谓的针对大型语言模型(LLMs)的“越狱”——这些攻击需要大量的人类智慧,并且在实践中很脆弱。自动对抗性提示生成的尝试也取得了有限的成功。在本文中,我们提出了一种简单有效的攻击方法,可以导致对齐的语言模型生成令人反感的行为。 阅读详情

相关推荐

skill使用教程,从小白到大神进阶

(2)突然无法使用(NodeJS安装参考):如果正常使用中,突然发现claude命令无法启动claude-code了,可能是claude-code正在后台自动更新,等待几分钟后再尝试使用,如果还是不行,请先运行下列代码移除claude-code,注意,如果你的node安装目录不同,要替换成自己的安装目录:rm -rf /opt/homebrew/lib/node_modules/@anthropic-ai/claude-code。安装完成后,让我们启动 Claude Code,看看它长什么样。

weixin_45036829的博客 2020

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

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

AC_Dreameng 1420

IEEE ACCESS Please note that all author names should be listed in English.(所有作者名需用英文名列出)

很奇怪哈,我明明手稿和提交页面作者都是用的英文,但是为什么还是会提示我没用英文呢?后来给编辑发消息,回的很快,他给我发了一个截图,确实是出现中文,但是我还是不知道为啥会出现中文。直到晚上回寝室洗澡的时候忽然想起来了是不是orcid的原因,因为它会强制作者绑定一个orcid账号,而我的orcid账号的名字刚好是中文的。当然这个只是我的一个猜想,但是我觉得可能性很大。我的第二篇论文已经投稿了快三个月了,效果非常的不好,所以我打算转投IEEE ACCESS了,希望这里可以给我一点好的建议。

kuyecsl的博客 3320

【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

U盘文件变exe?3步教你用火绒+批处理脚本恢复隐藏文档(附注册表修复)

本文详细解析了U盘文件被病毒隐藏并伪装成exe文件的原理,并提供了三步解决方案:首先使用火绒安全软件进行全盘查杀清除病毒;其次通过批处理脚本批量恢复被隐藏的文件属性;最后修复被篡改的注册表设置,彻底解决文件无法显示的问题,帮助用户安全找回数据并加固系统防护。

weixin_28622215的博客 926

2021.11.23 Covins 多机器人单目协同建图 跑Euroc数据集 更新

近日,一直在调试如何使用Covins跑通数据集,因为是初学者,所以很多bug出来的时候原理都不懂,只能复制——百度——尝试解决的过程。 现分享一下近日的结果以及与Covins作者帮助解答的一些问题。 使用代码行跑依次跑Euroc多数据集 这里的意思是使用作者提供的covins_examples文件夹中的euroc_examples_mh123_vigba.sh文件,这个文件是将三个Euroc数据集依次运行,跑完第一个数据集,第二个数据集运行的时候在第一个数据集生成地图的基础上继续绘制,由于我只下载了两个数据

qq_42614598的博客 2477

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

如何在Tagetik系统中抽取处理SAP系统财务数据

如何在Tagetik系统中抽取处理不同核算系统财务数据:以SAP为例,简单讲一下Tagetik对接SAP数据的基本情况

2201_75401663的博客 583

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

10位PWM能否满足电梯±5mm平层精度?4位扩展法让10位PWM达到14位精度

电梯平层精度直接关系乘坐舒适性与安全性,而PWM分辨率是决定精度的关键因素之一。10位PWM能否满足±5mm的平层精度要求?本文从分辨率与物理量的对应关系出发,结合工程精度需求与实战对比,给出明确的选型结论与解决方案,请参考CSDN博客《4位扩展法:基于ATtiny816的高精度PWM软件扩展方法》和《低成本高精度PWM:4位扩展法原理、实现和工程实践》。10位PWM的分辨率为 $2^{10} = 1024$ 级。

m0_73354873的博客 250

MIPI C-PHY介绍(Specification for C-PHY V1.2)

本文档描述了一个名为C-PHY的高速串行接口,它在带宽有限(bandwidth limited channels,看的有人说C的含义就是channel limit)的通道上提供高吞吐量性能,用于连接到外设,包括显示器和摄像头。首先0x4fff在0x4000~0x4fff区域,则f=(0,0,0,0,0,0,1),顺序是S6~S1;最后,端到端的传输过程是什么样呢,如下图所示,16bit先转换成7个符号(每个符号3位,共21位),然后并行数据转换成串行数据,输送到符号编码器和3个线的驱动器,接收端流程相反。

qflook的博客 5911

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

论文复现5:UMI Universal Manipulation Interface

UMI 采用手持式夹具,加上精心的界面设计,可实现便携式、低成本和信息丰富的数据收集,以进行具有挑战性的双手和动态操作演示。配备这些功能后,UMI 框架解锁了新的机器人操作功能,只需更改每个任务的训练数据,即可实现零样本可推广的动态、双手、精确和长视野行为。我们通过全面的现实世界实验展示了 UMI 的多功能性和有效性,其中通过 UMI Zeroshot 学习的策略在对不同的人类演示进行训练时可以推广到新的环境和对象。项目主页:https://umi-gripper.github.io/

github_38060285的博客 1995

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

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

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

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

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

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

renew 746

pscad IEEE标准系统搭建说明

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

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

线段树 区间更新 区间查询 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(线段树区间更新)

题意: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

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(线段树应用之:区间更新,区间查询)

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 (线段树区间更新)

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

aocang4831的博客 149

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

A Simple Problem with Integers,题目链接 ,click here DescriptionYou 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

不念过往 , 不愧恒心 375
上一篇: Poj3264 Balanced Lineup 线段树基础题
下一篇: Poj1611 The Suspects 并查集基础题
Megumin
博客等级 码龄10年 3粉丝 89原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值