poj 3468 A Simple Problem with Integers(线段树)

Gromacs文件格式全解析:xtc vs trr vs cpt,哪种更适合你的模拟需求? 本文深入解析Gromacs分子动力学模拟中的三种核心文件格式xtc、trr和cpt,详细对比其技术特性和适用场景。xtc适合存储效率优先的场景,trr保留完整动力学数据,cpt确保模拟精确重启。通过实际配置示例和存储优化技巧,帮助用户根据模拟需求选择最佳格式组合,平衡分析灵活性与存储成本。 阅读详情
H - A Simple Problem with Integers

Crawling in process...Crawling failedTime Limit:5000MS    Memory Limit:131072KB    64bit IO Format:%I64d & %I64u

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.

 

 

这道题是我最痛苦的一次,思路很快出来,敲的也快,可惜却因为敲少了个+号,少了个和,少了个long long ,却是绝大部分数据都OK,花了一个下午的狂调

 

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define N 100300
using namespace std;
class node
{
  public:
  int l,r;
  long long sum,lazy;
}root[4*N];
long long shu[N];
void build(int t,int l,int r)
{
  root[t].l=l;root[t].r=r;root[t].lazy=0;
  if(root[t].l==root[t].r){cin>>root[t].sum;return;}
  build(t<<1,l,(l+r)/2);build(t<<1|1,(l+r)/2+1,r);
  root[t].sum=root[t<<1].sum+root[t<<1|1].sum;
}
void update(int t,int l,int r,long long date)
{
  if(root[t].l==l&&root[t].r==r)
  {root[t].sum+=(root[t].r-root[t].l+1)*date;root[t].lazy+=date;return;}//这里的+原下没加WA
  else
  {
    if(root[t].lazy!=0)
    {
      root[t<<1].lazy+=root[t].lazy;root[t<<1|1].lazy+=root[t].lazy;
      root[t<<1].sum+=(root[t<<1].r-root[t<<1].l+1)*root[t].lazy;
      root[t<<1|1].sum+=(root[t<<1|1].r-root[t<<1|1].l+1)*root[t].lazy;
      root[t].lazy=0;
    }
    if(root[t<<1].r>=r)update(t<<1,l,r,date);
    else if(root[t<<1|1].l<=l)update(t<<1|1,l,r,date);
    else {update(t<<1,l,root[t<<1].r,date);update(t<<1|1,root[t<<1|1].l,r,date);}
    root[t].sum=root[t<<1].sum+root[t<<1|1].sum;//这个很关键没加WA
  }
}
long long query(int t,int l,int r)
{
  long long s;
  if(root[t].l==l&&root[t].r==r)return root[t].sum;
  else
  {
    if(root[t].lazy!=0)
    {
      root[t<<1].lazy+=root[t].lazy;root[t<<1|1].lazy+=root[t].lazy;
      root[t<<1].sum+=(root[t<<1].r-root[t<<1].l+1)*root[t].lazy;
      root[t<<1|1].sum+=(root[t<<1|1].r-root[t<<1|1].l+1)*root[t].lazy;
      root[t].lazy=0;
    }
   if(root[t<<1].r>=r)s=query(t<<1,l,r);
   else if(root[t<<1|1].l<=l)
   s=query(t<<1|1,l,r);
   else s=query(t<<1,l,root[t<<1].r)+query(t<<1|1,root[t<<1|1].l,r);

  }
  return s;
}
int main()
{
  int n,m;

   scanf("%d%d",&n,&m);
  build(1,1,n);
  char f;
  long long a,b,c;
  for(int i=0;i<m;i++)
  {
    cin>>f>>a>>b;
    if(f=='C')
    {
      cin>>c;
      update(1,a,b,c);
    }
    else
    cout<<query(1,a,b)<<"\n";
  }

}


 

(Cascade extended state observer)级联ADRC的simulink仿真和程序---送给中国研究学者的精华版 (Cascade extended state observer)级联ADRC的simulink仿真和程序---送给中国研究学者的精华版 阅读详情

相关推荐

从零开始 使用OMNET++结合VEINS,INET和SUMO的联合仿真

搭建仿真的环境,导入VEINS和INET开源库,使用INET库中提供的网络协议和功能模型来模拟通信协议和网络功能,使用SUMO创建道路网络和车辆轨迹,并导出到OMNeT++中 在OMNeT++中使用VEINS通过socket和SUMO连接,借助VEINS实现的TRACI接口来设置车辆相关的行为和场景,最后在OMNET++中结合VEINS,SUMO和INET运行联合仿真实验,并分析车辆在遇到紧急情况下的通信状况和具体行为

mjmmm的博客 1万+

【线段树】POJ 3468 A Simple Problem with Integers

POJ 3468 A Simple Problem with Integers 题意:区间修改,区间查询 思路:模板题 #include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <cmath> #include <cs...

L_X_ 173

vue3接入大华摄像头

┃ ┃ ┣ 📜PlaybackModal.vue 回放列表模态框。┃ ┃ ┗ 📜VideoGrid.vue 视频播放区域。┃ ┃ ┣ 📜ControlPanel.vue 控制面板。┃ ┃ ┣ 📜DeviceList.vue 设备列表。┃ ┣ 📂module //大华摄像头文件。

💻 专注 Vue 前端与 Java 后端技术 🌱 目前正在深入 Spring Boot、微服务与性能优化 📝 定期分享实战踩坑经验与学习笔记 🤝 欢迎交流,共同进步 920

POJ3468,A Simple Problem with Integers,线段树

题目链接: POJ3468 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 77541   Accepted: 23874 Case Time Limit: 2000MS Descrip

北 496

NVIDIA NCCL 源码解析:从XML拓扑到高性能通信图的构建

本文深入解析了NVIDIA NCCL如何将XML硬件拓扑文件转化为高性能通信图的核心过程。详细阐述了从创建CPU、GPU、NIC等节点,到建立PCIe、NVLink连接,再到计算链路带宽并进行关键排序的完整建图流程。该图是NCCL实现最优通信路径规划、充分发挥NVLink等高速互联性能的基石,直接影响分布式深度学习训练的效率。

convnet3designer的博客 315

UE4逆向实战:如何快速定位UWorld和GName的5种实用技巧(含版本差异分析)

本文详细介绍了UE4逆向工程中快速定位UWorld和GName的5种实用技巧,包括特征码定位法、动态行为分析法、静态符号分析法等,并针对不同版本差异提供了适配方案。特别强调了UWorld作为游戏世界核心容器和GName作为名称管理系统的重要性,帮助开发者高效进行游戏逆向分析。

star的博客 911

POJ 3468 A Simple Problem with Integers 线段树

线段树模版题。 贴个代码。 #include #include #include #include #include #include #include #include #include #include #include #include #define PI acos(-1.0) #define Max 100005 #define inf 1<<28 using

just_water 1329

最优化问题——一维搜索(一)

最优化问题——一维搜索 1. 一维搜索的引入 1.1 从非线性规划问题到一维搜索 在前面的文章中,我们提到了基于迭代的非线性规划问题的求解思路。在求解过程中,我们提到了在每一步的迭代中都需要对计算步长因子,其计算公式为: λk=minλf(xk+λp)λ_k=min_{λ}f(x_k+λp)λk​=minλ​f(xk​+λp) 我们将f(xk+λp)f(x_k+λp)f(xk​+λp)视为λ的一元函数,我们的目标就是求这个一元函数的极小值。对于这个问题,我通常的求解方式为一维搜索。 1.2 一维搜索的基本形

hei653779919的博客 7379

POJ 3468 A Simple Problem with Integers 线段树

题目链接:http://poj.org/problem?id=3468 题型:线段树 以下是参考大神的代码写的!! #include #include #include #include #include #include #include #include #define Lson left ,mid, rt<<1 #define Rson mid+1,right,rt<<1|1 #

PWZER 540

R语言机器学习 频谱分析

由傅里叶理论可知,时域中的任何信号都可以由一个或多个具有适当频率、幅度和相位的正弦 波叠加而成。也就是说,任何时域信号都可以变换成相应的频域信号,通过频域测量可以得到信号在某个特定频率.上的能量值。频谱分析就是在频域上分析时间序列的方法,它使用傅里叶分析方法,将时域信号转换到频域,并从频域中找出信号频谱的变化规律。原始周期图不是谱密度的一致估计量,但相邻值是渐近独立的。0点的周期图在理论上是0,因为去掉了级数的均值(但这可能会受到渐减的影响):在平滑过程中,它被相邻值的插值所取代,并且该频率不返回任何值。

Mrrunsen的博客 1188

北斗导航 | 从北一到北二再到北三,你应该知道的北斗导航系统

博主github:https://github.com/MichaelBeechan 博主CSDN:https://blog.csdn.net/u011344545 一、引言 我国高度重视北斗系统的建设和发展。自20世纪80年代开始探索适合我们国家国情的卫星导航系统发展道路,形成了“三步走”的发展战略:2000年底,建成北斗一号导航系统,向我国广大用户提供服务;2012年底,建成北斗二号导航系统,...

尘世冰封的专栏 3092

线段树 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 number to each number in a given interval. The other i

Advanced_hwr的博客 683

机器视觉工程师如何进行高速运动物体捕获

硬件方面使用高帧率相机(如工业相机、高速摄像机)确保充足的光照条件使用高性能计算平台减少处理延迟软件方面背景减除技术快速分离运动物体卡尔曼滤波预测物体轨迹ROI技术减少计算量多线程处理提高实时性实际应用中的关键考量针对特定场景调整参数(如阈值、滤波器参数等)平衡计算资源与实时性要求结合特定领域知识优化算法(如物体运动特性)上述示例代码实现了一个基础的高速物体跟踪系统,通过背景减除和卡尔曼滤波实现对高速物体的检测和跟踪。

zhangzhechun_02的博客 632

【线段树】A Simple Problem with Integers poj ——3468

A Simple Problem with Integers You have NNN integers, A1,A2,...,ANA1, A2, ... , ANA1,A2,...,AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each...

我の名字 227

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

InTheHand.Net.Personal+BlueTooth4,蓝牙开发

项目中有蓝牙开发的必备dll,现在网上相关的文档博客不少,有的说的多有的说少,但是却很少有这两个dll,分享一下。

POJ3468 A Simple Problem with Integers 线段树

A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 152613 Accepted: 47315 Case Time Limit: 2000MS Description You have N integers, A1, A2, … , AN. You need to...

DouglasConnor的博客 218

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

POJ - 3468 A Simple Problem with Integers 经典线段树问题

POJ - 3468  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 g...

GYH0730的博客 312

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

POJ3468 A Simple Problem with Integers 线段树成段更新

传送门:POJ3468 题意:给定n个数和两种操作,Q  i   j    代表求Σnum[t](i 思路:线段树基本操作,成段更新,区间询问。也可以用树状数组做,详见挑战程序设计第二版P179. 代码: #include #include #include #include #include #include #include #include #include #include #de

WA是一笔财富 367

POJ 3468 A Simple Problem with Integers(线段树 ,延迟标记)

题目链接:http://poj.org/problem?id=3468    今天终于把电脑的输入法修好了!!终于可以多写一点了~具体解释在代码中,本题代码也可以作为线段树区间更新的模板O(∩_∩)O~ #include #include using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define

614

POJ 3468 A Simple Problem with Integers(线段树)

题目地址:http://poj.org/problem?id=3468 思路:updata()区间增减,query()区间求和,会超int用long long AC代码: #include #include #include #include #include #include #include #include #include #include #include

Java识堂,一个有干货的微信公众号 376

POJ 3468 A Simple Problem with Integers 【线段树】

题目链接 http://poj.org/problem?id=3468 思路 线段树 区间更新 模板题 在赋初始值的时候,按点更新区间就可以 AC代码 #include <cstdio> #include <cstring> #include <ctype.h> #include <cstdlib&g...

dianxi0949的博客 65

[线段树] 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 number to each number in a given interval. The other is to...

weixin_44197056的博客 113

【POJ3468】【zkw线段树】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 othe...

Gregory99174的博客 279

POJ3468 线段树A Simple Problem with Integers

我还是第一次见一会对 一会不对的评测系统。。。一样的代码 一次对一次不对?? #include<iostream> #include<algorithm> #include<cstring> #define lc rt<<1 #define rc rt<<1|1 using namespace std; const int maxn ...

lizhenhao 153

poj3468A Simple Problem with Integers 线段树

//两个操作,第一个区间[a , b]内的所有数加c //第二个询问区间[a , b]的值 //很标准的线段数 #include #include #include using namespace std ; const int maxn = 1e5+10 ; #define left v #define right v typedef __int64 ll ; ll h[m

ijbuhv的专栏 807

[线段树] poj3468 A Simple Problem with Integers

重新把以前的线段树内容写了一遍~~ 线段树还要继续加强~~ 具体的分析可以看这里~ poj3468题解#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> using namespace std; typedef long long LL; const int INF = 0x3f3f3f3f

童凌的技术博客 460

[POJ 3468] A Simple Problem with Integers 线段树解题报告

[POJ 3468] A Simple Problem with Integers 线段树题目描述输入输出题目大意解题思路源代码如下心得总结功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图...

谁取了我的ID:gz007的博客 323
上一篇: hdu 2795 Billboard(线段树)
下一篇: nefu 三国之战
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址