POJ 3468 A Simple Problem with Integers

STM32 HAL 硬件IIC驱动BNO085:从移植到姿态解算全流程解析(附源码) 本文详细解析了STM32 HAL库下硬件IIC驱动BNO085 IMU传感器的全流程,包括CubeMX配置、驱动移植、传感器初始化、Q格式数据处理及四元数转欧拉角解算。提供了完整的源码实现和常见问题解决方案,帮助开发者快速掌握高精度姿态测量技术。 阅读详情

A Simple Problem with Integers

https://vjudge.net/problem/POJ-3468
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.
C++

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int MAXN = 100000 + 10;
typedef long long LL;

LL num[MAXN];

struct node{
	int l, r;
	LL lazy, sum;
}segTree[MAXN << 2];

void pushup(int x)
{
	segTree[x].sum = segTree[x << 1].sum + segTree[x << 1 | 1].sum;
}

void pushdown(int x)
{
	if(segTree[x].lazy)
	{
		segTree[x << 1].lazy += segTree[x].lazy; 
		segTree[x << 1 | 1].lazy += segTree[x].lazy;
		segTree[x << 1].sum += (segTree[x << 1].r - segTree[x << 1].l + 1) * segTree[x].lazy;
		segTree[x << 1 | 1].sum += (segTree[x << 1 | 1].r - segTree[x << 1 | 1].l + 1) * segTree[x].lazy;
		segTree[x].lazy = 0;
	}
}

void build(int x, int l, int r)
{
	segTree[x].l = l;
	segTree[x].r = r;
	segTree[x].lazy = 0;
	if(l == r)
	{
		segTree[x].sum = num[l];
		return;
	}
	int mid = l + r >> 1;
	build(x << 1, l, mid);
	build(x << 1 | 1, mid + 1, r);
	pushup(x);
}

void update(int x, int l, int r, LL val)
{
	if(l <= segTree[x].l && segTree[x].r <= r)
	{
		segTree[x].sum += (segTree[x].r - segTree[x].l + 1) * val;
		segTree[x].lazy += val;
		return;
	}
	pushdown(x);
	int mid = segTree[x].l + segTree[x].r >> 1;
	if(r <= mid) update(x << 1, l, r, val);
	else if(l > mid) update(x << 1 | 1, l, r, val);
	else
	{
		update(x << 1, l, mid, val);
		update(x << 1 | 1, mid + 1, r, val);
	}
	pushup(x);
}

LL query(int x, int l, int r)
{
	if(l <= segTree[x].l && segTree[x].r <= r)
		return segTree[x].sum;
	pushdown(x);
	int mid = segTree[x].l + segTree[x].r >> 1;
	if(r <= mid) return query(x << 1, l, r);
	else if(l > mid) return query(x << 1 | 1, l, r);
	else return query(x << 1, l, mid) + query(x << 1 | 1, mid + 1, r);
}

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i ++)
		scanf("%lld", &num[i]);
	build(1, 1, n);
	char op;
	int a, b;
	LL c;
	for(int i = 0; i < m; i ++)
	{
		getchar();
		scanf("%c", &op);
		if(op == 'Q')
		{
			scanf("%d%d", &a, &b);
			printf("%lld\n", query(1, a, b));
		}
		else
		{
			scanf("%d%d%lld", &a, &b, &c);
			update(1, a, b, c);
		}
	}
	return 0;
}
芒果YOLOv7改进48:主干篇:独家首发改进:目标检测新范式骨干PPHGNetv2改进版,充分融合信息特征,提升YOLOv7检测能力 YOLOv7代码改进实践 | 独家首发改进 PPHGNetv2 改进版结构 阅读详情

相关推荐

OpenHarmony v4.1 Release设置应用随系统自动启动

OpenHarmony 4.1 版本中的 Ability Manager Service (AMS) 提供了应用自启动管理功能,允许系统控制哪些应用可以在系统启动时自动运行。这需要以下两个主要步骤:启用系统的自启动管理支持开发一个系统应用来管理自启动配置。

afufufufu的博客 1898

poj 3468 A Simple Problem with Integers

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82832#problem/C A Simple Problem with Integers Time Limit:5000MS     Memory Limit:131072KB     64bit IO Format:%I64d & %I64u Submit Sta

大太阳 727

485芯片AB波形正负半周的问题探讨

      本人做的一个产品,产品的其中一个接口是RS485的,我们使用的芯片是MAX13487E。MCU是STM32F103,MCU的USART通过光耦隔离后,接到MAX13487E。因为STM32F103的VCC是3.3V的,MAX13487E的VCC是5V。      部分原理图如下,上述部分电路参考了官方的参考设计,现在测试的AB波形时候发现如下问题。1.把R10和R16改为1k,示波器C...

qq_26308521的博客 1万+

A Simple Problem with Integers POJ - 3468

A Simple Problem with Integers POJ - 3468 整理一下之前刷过的题 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 numbe...

ldu_商正昌的博客 241

Anthropic API接入指南:连接失败、403鉴权与Claude Code集成排查

在AI应用开发中,API接入与鉴权机制是开发者绕不开的基础工程问题。无论是调用云端模型服务还是自建网关,网络连通性、HTTP状态码语义、模型路由映射都会直接影响服务可用性。本文从通用的网络诊断与鉴权原理出发,梳理了从TCP连接失败到403权限拒绝的典型链路,并深入解析网关模型路由匹配机制。在此基础上,进一步说明如何通过环境变量完成Claude Code与VS Code的本地集成,以及一套基于Python的可复现接入方案。内容涵盖Anthropic API高频报错定位、curl冒烟测试、SDK工程化实践,适合

weixin_28743405的博客 465

FreeRTOS系统CPU使用率统计

操作系统中CPU使用率是在软件架构设计中必须要考虑的一个重要性能指标。它直接影响到程序的执行时间以及优先级更高的任务能否实时响应的问题。而CPU使用率也不能过低,避免资源浪费。

灵哎惹,凌沃敏的博客 1378

POJ 3468 A Simple Problem with Integers

SOL:也是颗裸的Splay Tree。。。套模版就好了。改改预处理神马的就Ok啦。   /* * POJ 3468 模版题 */ # include # include using std::swap; using std::max; # define LL long long # define inf 1<<29 # define keytree

imut zcy,I promise You. 635

快速搭建SpringBoot3+Vue3+ElementPlus管理系统

快速搭建SpringBoot3+Vue3管理系统前端项目搭建(默认开发环境:node20,Jdk17)创建项目并下载依赖--执行以下命令 前端项目搭建(默认开发环境:node20,Jdk17) 创建项目并下载依赖–执行以下命令 创建项目 yarn create vite admin-vue --template 2.下载依赖(也可按需下载) yarn add echarts --save yarn add vue-router --save yarn add element-plus --save y

adingyb的博客 2817

【线段树】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_ 172

Android Studio安装常见问题详解——Android Emulator Hypervisor Driver for AMD Processors installation failed.

目录一、问题描述二、解决方案2.1 开启CPU虚拟化2.2 禁用Hyper-V2.3 使用管理员命令行在驱动程序包中执行“silent_install.bat” 一、问题描述 新买的AMD轻薄本,在安装Android Studio时遇到问题: Android Emulator Hypervisor Driver for AMD Processors installation failed. 笔记本配置为: 二、解决方案 2.1 开启CPU虚拟化 设置虚拟化的步骤这里不进行详细介绍了。如果需要,可以自行百

Wendy的博客 4万+

焊缝缺陷智能检测:基于 YOLO 的工业质检系统实战

从焊缝缺陷数据集的构建到模型训练,从桌面检测界面到缺陷统计输出,本文覆盖了一套工业焊缝质检系统的完整路线。这个场景的核心难点在数据层面——气孔和裂纹这类小目标的标注质量直接决定了模型的最终表现。建议先在开源数据集上跑通全链路,确认 mAP 达到可接受的水平后,再通过补充特定类型的小目标数据和提升输入分辨率来做精度优化。工业场景中,漏检一个气孔的成本和误报一个假阳性的成本不一样——根据对两类成本的承受力,调整置信度阈值来找到业务上的最佳平衡点。

m0_71589036的博客 202

【POJ 3468】A Simple Problem with Integers

树状数组的新用途——带修改的区间和~

Regina8023 766

UG\NX二次开发 获取三平面交点

//如果返回值不为0 则此三个面没交点 int three_faces_point(tag_t tagFace1, tag_t tagFace2, tag_t tagFace3, double *dou_x, double *dou_y, double *dou_z)

王牌飞行员_里海的博客 674

poj3468 A Simple Problem with Integers

A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 31654   Accepted: 8984 Case Time Limit: 2000MS Description You have

喵呜的Blog 1019

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

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

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

POJ3468-A Simple Problem with Integers

http://poj.org/problem?id=3468 #include<cstdio> #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define LL long long using namespace std; const int maxn=100001; LL sum[ma...

weixin_30359021的博客 102

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

POJ-3468-A Simple Problem with Integers

POJ-3468 A Simple Problem with Integers 这道题线段树模板题,线段树区间求和区间修改 题目多次询问,遇到C修改区间,遇到Q求和 lay-tag方法 sum[]数组记录区间和 add[]记录结点是否用到tag原理。向下更新的时候重新将值置0. 同样记得向上更新 lazy-tag原理是当修改的是一整块区间时,只对这个线段区间进行整体修改,内部的每个元素先不做修改,...

qq_44624316的博客 188

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

POJ3468 A Simple Problem with Integers

线段树子区间更新维护 #include struct interval_tree{ int nums[100010]; struct Node{ long long mark, sum; } node[100010 << 2]; void build(int l, int r, int i) { if (l == r) {no

王旻宇 450

POJ3468 A Simple Problem with Integers 分块

题目链接 http://poj.org/problem?id=3468 分析 将原序列划分成若干段长度为 ⌊n⌋\lfloor \sqrt{n} \rfloor⌊n​⌋ 的区间进行维护; 设 a[i]a[i]a[i] 以表示原序列每个元素, b[i]b[i]b[i] 表示每个元素所属的区间, sum[i]sum[i]sum[i] 表示每个区间的元素之和,add[i]add[i]add[i] 表示每...

Kevin的博客 466

POJ 3468 A Simple Problem with Integers Splay

题目链接:http://poj.org/problem?id=3468 思路:这个题目很明显可以用线段树来做,但是这篇文章主要是讲一下Splay的做法。 Splay : Splay其实就是一种平衡树,它具有BST的特性,但是因为BST最坏情况下建树复杂度会达到O(n),Splay就是一种建立在BST之上,加入了一些旋转,使得退化成链的BST树的均摊复杂度为O(logn)。Splay最重要的就

Chris_Home 957
上一篇: POJ 3264 Balanced Lineup
下一篇: 第二届“传智杯”全国大学生IT技能大赛(决赛)部分题解
剑气扬名
博客等级 码龄7年 24粉丝 79原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值