bzoj 3212: Pku3468 A Simple Problem with Integers 线段树

halcon知识:常见三种模板匹配方法总结 halcon的三种模板匹配方法总结,halcon有三种模板匹配方法:即Component-Based、Gray-Value-Based、Shaped_based,分别是基于组件(或成分、元素)的匹配,基于灰度值的匹配和基于形状的匹配,此外还有变形匹配和三维模型匹配也是分属于前面的大类 本文只对形状匹配做简要说明和补充: Shape_Based匹配方法: 上图介绍的是形状匹配做法的一般流程及模板制作的两种方法。 先要补充点知识:形状匹配常见的有四种情况 一般形状匹配模板shape_model、线性变 阅读详情

                                          bzoj 3212 线段树模板题

传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3212


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. 

这是bzoj中难得的模板题~~~~~

#include<cstdio>
#include<iostream>
#define MAXN 800010

using namespace std;

char op[10];int n,m;
struct Segtree{
  #define lc(x) x<<1
  #define rc(x) ((x<<1)|1)
  int l[MAXN],r[MAXN];
  long long add[MAXN],s[MAXN];
  void update(int x)
  {
    s[x]=s[lc(x)]+s[rc(x)];

  }
  void push(int x)
  {
     s[lc(x)]+=add[x]*(r[lc(x)]-l[lc(x)]+1);
     s[rc(x)]+=add[x]*(r[rc(x)]-l[rc(x)]+1);
     add[lc(x)]+=add[x];
     add[rc(x)]+=add[x];
     add[x]=0;
  }
  long long  query(int x,int L,int R)
   {
       push(x);
      if(l[x]>R||r[x]<L)
        return 0;
      if(l[x]>=L&&r[x]<=R)
        return s[x];
      return query(lc(x),L,R)+query(rc(x),L,R);
   }
   void change(int x,int L,int R,int v)
   {
      push(x);
     if(l[x]>R||r[x]<L)
        return ;
     if(l[x]>=L&&r[x]<=R)
        {
            s[x]+=v*(r[x]-l[x]+1);
            add[x]=v;
            return ;
        }
        change(lc(x),L,R,v);
        change(rc(x),L,R,v);
        update(x);
   }
   void build(int x,int L,int R)
   {
       l[x]=L,r[x]=R,add[x]=0;
       if(L==R)
       {
           scanf("%lld",&s[x]);
           return ;
       }
       int mid=(L+R)/2;
       build(lc(x),L,mid);
       build(rc(x),mid+1,R);
       update(x);
   }
}seg;
int main()
{
   scanf("%d%d",&n,&m);
   seg.build(1,1,n);
   while(m--)
   {
      scanf("%s",op);
      if(op[0]=='C')
      {
          int l,r;long long  v;
          scanf("%d%d%lld",&l,&r,&v);
          seg.change(1,l,r,v);
      }
      else
      {
         int l,r;
         scanf("%d%d",&l,&r);
         printf("%lld\n",seg.query(1,l,r));
      }
   }
   return 0;
}


【3天快速入门WPF】1-从最简单的xaml开始 首先我们要知道xaml语法中声明即定义,意思就是“见到元素就相当于创建实例”,MainWindow.xaml的主干是一个元素里包含着一个 元素。这段程序就是在定义一个Window类的实例,这个实例的一个组成部分是一个Grid类的实例。 阅读详情

相关推荐

ESP-CSI:使用ESP32进行CSI(信道状态信息)采集

使用esp32进行csi(信道状态信息)采集和处理

capsize的博客 8280

BZOJ 3212: Pku3468 A Simple Problem with Integers【树状数组||线段树】

3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 128 MB Description You have N integers, A1, A2, … , AN. You need to deal with two kinds of operations. One type of o...

XSamsara的博客 AFO 273

AMD显卡跑Ollama大模型?手把手教你搞定Windows下GPU识别与加速(以RX 9600XT为例)

本文详细指导如何在Windows系统下使用AMD显卡(如RX 9600XT)运行Ollama大模型,解决GPU识别与加速问题。通过获取非官方Ollama版本、替换ROCm库文件等步骤,实现高效的GPU加速推理,提升大语言模型的运行效率。

weixin_28707365的博客 481

bzoj3212: Pku3468 A Simple Problem with Integers(线段树)

3212: Pku3468 A Simple Problem with Integers 题目:传送门 题解:    感谢Rose_max大佬的倾情相(推)助(水题)    一起打线段树啊~~~~ 代码: 1 #include<cstdio> 2 #include<cstring> 3 #include...

weixin_30443895的博客 133

ANSYS拓扑优化基础实例

唐深51CAE 2018/6/10 拓扑优化在工程设计中,常用于机械结构概念设计和轻量化设计,ANSYS通用有限元分析软件提供了强大的拓扑优化功能,本文将通过一个简单实例进行展示。 一、赵州桥 赵州桥又称安济桥,坐落在河北省赵县洨河上,建于隋朝年间公元595年~605年,由著名匠师李春设计建造,距今已有约1500年的历史,是当今世界上现存最早、保存最完整的古代敞...

TQT_CAE的博客 6026

基于STM32的RS485土壤氮磷钾与PH传感器数据采集与OLED显示实战(附完整代码)

本文详细介绍了基于STM32单片机通过RS485协议采集土壤氮磷钾与PH传感器数据的实战项目。涵盖硬件选型、连接方法、Modbus-RTU通信协议解析、STM32程序实现及OLED显示,提供完整代码和调试技巧,适用于农业物联网环境监测系统。

kotlin6android的博客 335

[bzoj 3212]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 ...

galiqing的博客 220

长短期记忆网络(LSTM)预测模型及其Python和MATLAB实现

LSTM 通过独特的门控机制解决了传统 RNN 的梯度消失和梯度爆炸问题,使其在处理长序列时具有显著优势。随着技术的不断发展,LSTM 及其变种(如 Bi-directional LSTM、Stacked LSTM 等)有望在更复杂的任务中发挥重要作用。2. **可视化真实值和预测值**:通过绘图来比较真实值和预测值,判断模型的准确性。2. **输入门(Input gate)**:决定当前的输入信息对细胞状态的影响。1. **细胞状态(Cell state)**:保持信息在时间步之间的传递。

qq_45441438的博客 2055

BZOJ3212 A Simple Problem with Integers

3212: Pku3468 A Simple Problem with IntegersTime Limit: 1 Sec Memory Limit: 128 MB Submit: 1277 Solved: 559 [Submit][Status][Discuss] DescriptionYou have N integers, A1, A2, … , AN. You need to de

DCrusher's blog 654

C++笔试题整理

目录 1. 笔试题1 1.1 链表反转 1.2 String 2. 笔试题2 2.1 求下面函数的返回值(微软) 2.2 什么是“引用”?申明和使用“引用”要注意哪些问题? 2.3 将“引用”作为函数参数有哪些特点? 2.4 在什么时候需要使用“常引用”?  2.5 将“引用”作为函数返回值类型的格式、好处和需要遵守的规则? 2.6 “引用”与多态的关系? 2.7 “引用”与指针的区别是什么? 2.8 什么时候需要“引用”? 2.9 结构与联合有和区别? 2.10 下面关于.

星月相随的专栏 2483

【树莓派安装Homeassistant及基本配置】

时隔一年,我又重新开始玩Homeassistant,发现其中奥妙无穷,惊喜不断。在我浅薄的认知中要学好嵌入式,必须玩过Homeassistant,并且玩出自己的名堂!因为这是最贴切实际的生活应用没有之一,每月更新使得唯有活水来;拥抱大千使得永葆青春的活力;鬼斧神工的操作精彩纷呈,可以堪称软件与硬件的完美落地!

vor234的博客 1万+

bzoj 3212 线段树

  裸的线段树 /************************************************************** Problem: 3212 User: BLADEVIL Language: Pascal Result: Accepted Time:100 ms Memory:19756 kb ***...

weixin_34302798的博客 127

c#【保姆级教程】基于System.Text.Json 支持多态类型序列化! 手把手教你实现一个通用的 PolymorphicJsonConverter!

我们需要自己实现一个继承自的转换器,在序列化时记录具体类型,在反序列化时根据类型标识还原成正确的子类对象。public abstract class WorkStepBase { /* 抽象方法等 */ }public class Person : WorkStepBase { /* 实现 */ }public class Product : WorkStepBase { /* 实现 */ }特性说明✅ 自动发现子类无需手动维护类型列表,自动扫描程序集✅ 类名映射。

一个编程的同学 425

bzoj 3212: Pku3468 A Simple Problem with Integers (线段树)

3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 1565  Solved: 676 [Submit][Status][Discuss] Description You have N integers, A1, A2, ... , AN. You

clover_hxy的博客 451

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

BZOJ 3212 Pku3468 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'm Growing 355

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

BZOJ3212 Pku3468 A Simple Problem with Integers 题解

题目大意:   一个数列,有两个操作:1.修改操作,将一段区间内的数加上c;2.查询操作,查询一段区间内的数的和。 思路:   线段树裸题,区间修改、区间查询,维护和以及加上的数,由于无序,不需要向下推标记,只需在子树更新完之后更新根节点即可。 代码: 1 #include<cstdio> 2 #include<cstring> 3 #in...

diyaochang9767的博客 139

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

BZOJ 3212【Pku 3468】A Simple Problem with Integers==线段树裸题

题目传送:23333 直接建树,区间修改可以打永久标记,查询直接查就可以了。 记得要开long long==我不知道不开会不会WA反正我开了 #include #include #include #include #define rep(j,k,l) for (long long j=k;j<=l;j++) using namespace std; long

YYMHL 292

【bzoj 3212】【POJ 3468】A Simple Problem with Integers(线段树)

寒乍起,孤寂伴,长立风中,愿为风散

reverie_mjp的博客 3363

BZOJ3212 Pku3468 A Simple Problem with Integers

线段树 题目传送门 全裸线段树 代码: #include&lt;cctype&gt; #include&lt;cstdio&gt; #include&lt;cstring&gt; #include&lt;algorithm&gt; #define N 100005 #define F inline using namespace std; typedef long long LL; s...

forezxl的博客 259

[BZOJ3212] Pku3468 A Simple Problem with Integers

传送门http://www.lydsy.com/JudgeOnline/problem.php?id=3212题目大意区间修改,区间查询和题解水题const maxn=100005; type aa=record l,r:longint; val,tag:int64; end; var w:array[0..8*maxn]of aa; i,j,k:longint; n,m:longi

slongle的专栏 447

BZOJ3212: Pku3468 A Simple Problem with Integers

【传送门:BZOJ3212】 简要题意:   给出一段序列,有两种操作:  1.Q l r求出l到r的和   2.C l r c将l到r的值加c 题解:   线段树水题   区间修改+区间询问,加个标记处理   注意加long long 参考代码: #include<cstdio> #include<cstdlib> #include&...

weixin_30278237的博客 80

bzoj 3212: Pku3468 A Simple Problem with Integers

3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 1954  Solved: 857 [Submit][Status][Discuss] Description You have N integers, A1, A2, ... , AN. You

Brian551 's Home 323

bzoj3212 Pku3468 A Simple Problem with Integers 线段树

3212: Pku3468 A Simple Problem with IntegersTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 2046 Solved: 892[Submit][Status][Discuss] Description You have N integers, A1, A2, ... , AN. You need to dea...

weixin_30652879的博客 131
上一篇: bzoj 2005 [Noi2010]能量采集 数学
下一篇: bzoj 1406: [AHOI2007]密码箱 数学
DJS_K_D
博客等级 码龄12年 2粉丝 51原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值