NOJ1560---Let Slimes Grow Up(线段树)

科技中介服务机构想要提升服务效率,需要哪些数智工具支持?.docx 科技中介服务机构想要提升服务效率,需要哪些数智工具支持? 立即下载

问题描述
You know 8Mao has his own Slime Team. But he soon found that let the Slimes stand in a line and make them from low to high is a such stupid thing since the Slimes are so f[bi][bi]king stupid!
As a result, 8Mao decided to give up.
But 8Mao still want his Slime Team be beautiful. So he got up another idea, let his Slimes grow up. He got some medicine that can make the Slimes in the line get higher. But only can let continuous Slimes.
8Mao thought that the variance of the heights of Slimes in the line is smaller, the Slime Team is more beautiful.
You have to help 8Mao to calculate out the variance of Slimes in a continuous sequence.
输入
This problem contains several cases, ends with EOF.
The first line of each case contains 2 integers N and M which N indicates the number of Slimes and the number of operations.
Next line contains the heights of each Slimes ordered from 0 ~ N - 1. (0 < height <= 100, 000)
Then M lines followed. Each line indicates one operation.
If the operator is “1”, then follows 3 integers A, B and C which indicate the start number of the Slimes and the end number of the Slimes and the heights the Slimes between A and B will increase.
If the operator is “2”, then follows 2 integers A and B, you have to calculate out the variance of heights between Slime A and Slime B.
输出
For each operator “2”, you should output the variance. (The answer should be formatted to integer)
样例输入

5 3
1 4 3 2 5
2 0 4
1 1 2 2
2 0 4

样例输出

2
3

提示

无

来源

cjl

操作

要求区间内的方差,把方差公式转换以后,变成维护区间和和区间平方和,然后线段树乱搞下就行,
这题是去年校赛的,可惜那时太弱根本不会

/*************************************************************************
    > File Name: NOJ1560.cpp
    > Author: ALex
    > Mail: zchao1995@gmail.com 
    > Created Time: 2015年04月16日 星期四 20时22分13秒
 ************************************************************************/

#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
#include <set>
#include <vector>

using namespace std;

const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;

static const int N = 100100;
struct node
{
    int l, r;
    LL sum;
    LL sumsum;
    LL add;
}tree[N << 2];

void build(int p, int l, int r)
{
    tree[p].l = l;
    tree[p].r = r;
    tree[p].add = 0;
    if (l == r)
    {
        scanf("%lld", &tree[p].sum);
        tree[p].sumsum = tree[p].sum * tree[p].sum;
        return;
    }
    int mid = (l + r) >> 1;
    build(p << 1, l, mid);
    build(p << 1 | 1, mid + 1, r);
    tree[p].sum = tree[p << 1].sum + tree[p << 1 | 1].sum;
    tree[p].sumsum = tree[p << 1].sumsum + tree[p << 1 | 1].sumsum;
}

void pushdown(int p)
{
    if (tree[p].add)
    {
        tree[p << 1].add += tree[p].add;
        tree[p << 1 | 1].add += tree[p].add;
        int m = tree[p << 1].r - tree[p << 1].l + 1; //左子树长度
        LL use = tree[p].add;
        LL sum1 = tree[p << 1].sum;
        tree[p << 1].sum += use * m;
        tree[p << 1].sumsum += m * use * use + 2 * use * sum1;
        LL sum2 = tree[p << 1 | 1].sum;
        m = tree[p << 1 | 1].r - tree[p << 1 | 1].l + 1;
        tree[p << 1 | 1].sum += use * m;
        tree[p << 1 | 1].sumsum += m * use * use + 2 * use * sum2;
        tree[p].add = 0;
    }
}

void update(int p, int l, int r, LL val)
{
    if (tree[p].l == l && r == tree[p].r)
    {
        tree[p].add += val;
        int m = r - l + 1;
        LL sum = tree[p].sum;
        tree[p].sum += m * val;
        tree[p].sumsum += val * val * m + 2 * val * sum;
        return;
    }
    pushdown(p);
    int mid = (tree[p].l + tree[p].r) >> 1;
    if (r <= mid)
    {
        update(p << 1, l, r, val);
    }
    else if (l > mid)
    {
        update(p << 1 | 1, l, r, val);
    }
    else
    {
        update(p << 1, l, mid, val);
        update(p << 1 | 1, mid + 1, r, val);
    }
    tree[p].sum = tree[p << 1].sum + tree[p << 1 | 1].sum;
    tree[p].sumsum = tree[p << 1].sumsum + tree[p << 1 | 1].sumsum;
}

LL sumsum, sum;

void query(int p, int l, int r)
{
    if (l == tree[p].l && r == tree[p].r)
    {
        sum += tree[p].sum;
        sumsum += tree[p].sumsum;
        return;
    }
    int mid = (tree[p].l + tree[p].r) >> 1;
    pushdown(p);
    if (r <= mid)
    {
        query(p << 1, l, r);
    }
    else if (l > mid)
    {
        query(p << 1 | 1, l, r);
    }
    else
    {
        query(p << 1, l, mid);
        query(p << 1 | 1, mid + 1, r);
    }
}

int main()
{
    int n, m;
    while (~scanf("%d%d", &n, &m))
    {
        int op, x, y;
        LL val;
        build(1, 1, n);
        while (m--)
        {
            scanf("%d", &op);
            if (op == 1)
            {
                scanf("%d%d%lld", &x, &y, &val);
                ++x;
                ++y;
                update(1, x, y, val);
            }
            else
            {
                scanf("%d%d", &x, &y);
                ++x;
                ++y;
                sum = 0;
                sumsum = 0;
                query(1, x, y);
                double _x = sum * 1.0 / (y - x + 1);
                double ans = ((y - x + 1) * _x * _x - 2 * _x * sum + sumsum) * 1.0;
                ans /= (y - x + 1);
                cout << (LL)ans << endl;
            }
        }
    }
    return 0;
}
usb 扩容盘检测修复工具源码,编译产物 立即下载

相关推荐

融合UWB和IMU割草机定位EKF研究(Matlab代码实现)

内容概要:本文主要介绍了一个名为“Plecs全桥LLC谐振变换器仿真模型”的技术资源,该资源聚焦于电力电子领域中的LLC谐振变换器建模与仿真,涵盖开环、闭环控制、软启动设计及参数优化等核心内容。文档不仅提供了LLC变换器的详细建模方法与仿真案例,还系统梳理了其在高效电源转换系统中的应用,包括隔离型全桥拓扑结构的设计与性能分析。此外,资源汇总了大量Matlab/Simulink仿真模型及相关科研方向,涉及新能源并网、储能控制、电机驱动等多个前沿领域,全面展示LLC谐振变换器在现代电力系统中的关键技术实现路径。同时,文档附带多种学习资料获取途径,如网盘链接和公众号资源,便于研究人员深入实践与拓展研究。; 适合人群:具备扎实的电力电子、自动控制理论基础,从事新能源发电、开关电源设计、电力系统仿真等相关领域的研究生、工程师及科研人员。; 使用场景及目标:①深入理解LLC谐振变换器的工作原理、建模方法与控制策略;②开展电力电子变换器的仿真验证与参数优化设计;③支撑科研项目、学位论文或工程项目的系统仿真与方案验证; 阅读建议:建议结合所提供的仿真模型与参考文献,使用Plecs或Simulink软件进行动手实践,重点掌握LLC谐振变换器的建模流程、闭环控制设计、软启动机制及参数调试技巧,以全面提升在实际工程中的应用与创新能力。

noj 1560 Let Slimes Grow Up(线段树,lazy,暂未A)

noj 1560 Let Slimes Grow Up

yjCola 567

基于变频控制的多相交错LLC谐振变换器闭环仿真(Simulink仿真实现)

基于变频控制的多相交错LLC谐振变换器闭环仿真(Simulink仿真实现)内容概要:本文主要介绍了基于Plecs的全桥LLC谐振变换器仿真模型,涵盖变频控制下的多相交错LLC谐振变换器闭环仿真、V2G电动汽车ACDC整流与双向CLLC谐振变换器充放电仿真、LLC谐振变换器的开环与闭环软启动设计,以及储能系统中双向Buck-Boost变换器结合模型预测电流控制和电压下垂控制的仿真研究。同时,文档列举了多种电力电子系统与控制策略的Simulink/Plecs仿真案例,涉及三相交错并联Buck变换器、三电平Buck直流变换器、单相Boost PFC电路等,展示了丰富的电力变换器建模与控制技术。此外,还包括参数设计报告、计算书及相关参考文献,适用于从事电力电子、新能源发电、电动汽车充放电系统等领域的研究人员和技术开发人员。; 适合人群:具备电力电子、自动控制理论基础,从事新能源、电动汽车、电力系统等相关领域研究的研发人员、高校研究生及高年级本科生。; 使用场景及目标:① 学习和掌握LLC谐振变换器及其他典型电力电子变换器的工作原理与建模方法;② 实现闭环控制策略如变频控制、软启动、模型预测控制、下垂控制等的仿真验证;③ 支持科研项目、毕业设计或工程开发中的系统仿真与优化设计。; 阅读建议:建议结合文中提供的仿真模型、设计报告与参考文献,逐步搭建并调试相应系统,重点关注控制策略的实现细节与参数整定过程,以深入理解系统动态响应特性与控制性能。

hdu5172---GTY's gay friends

Problem Description GTY has n gay friends. To manage them conveniently, every morning he ordered all his gay friends to stand in a line. Every gay friend has a characteristic value ai , to express how

Alex 1850

西电计组实验一 存储器实验

计组实验报告 实验一 存储器实验——FPGA中LPM_ROM定制与读出实验 一.实验目的   1.掌握FPGA中lpm_ROM的设置,作为只读存储器ROM的工作特性和配置方法;   2.用文本编辑器编辑mif文件配置ROM,学习将程序代码以mif格式文件加载于lpm_ROM中;   3.在初始化存储器编辑窗口编辑mif文件配置ROM;   4.验证FPGA中mega_lpm_ROM的功能。 二.实验原理   ALTERA的FPGA中有许多可调用的LPM (Library Parameterized Modu

Polaris的博客 1万+

GPU架构-SIMT

本文深度剖析了GPU的SIMT架构,从硬件实现层面解析其与SIMD的本质差异。SIMT通过将32个线程捆绑为warp执行,在标量编程模型下实现数据并行。文章对比了SIMD和SIMT的执行模型、分支处理机制及存储层次,指出SIMT是对SIMD的虚拟化抽象。重点分析了Volta架构引入的独立线程调度技术,以及访存合并对性能的关键影响。通过定量数据展示了各代GPU架构的寄存器文件规模和线程调度机制,为开发者优化GPU程序提供了硬件层面的理论基础。

技术引领业务创新 974

hdu5141——LIS again

LIS again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 132    Accepted Submission(s): 34 Problem Description A numeric sequence of a

Alex 1773

CentOS7下用FreeRADIUS+AD实现802.1X认证完整指南(附华为交换机配置)

本文提供了在CentOS 7系统上部署FreeRADIUS并与Windows Active Directory集成,以实现企业级802.1X网络认证的完整实战指南。内容涵盖从架构原理、服务器配置(包括Kerberos、Samba Winbind集成)、FreeRADIUS核心设置与AD联动,到华为交换机的详细配置步骤。重点解决了生产环境中常见的高可用、动态VLAN下发及深度排错问题,为企业构建集中、安全的网络准入控制体系提供了经过验证的解决方案。

weixin_29273849的博客 407

Codeforces Round #291 (Div. 2)---C. Watto and Mechanism

Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the

Alex 1642

Open3D 高斯牛顿法优化的ICP点云配准

本文介绍了基于高斯牛顿法的ICP点云配准算法。算法通过最小化源点云与目标点云之间的误差函数,求解最优的刚性变换参数(平移向量和欧拉角)。核心内容包括:1)建立误差函数和目标函数;2)推导雅可比矩阵计算,特别是旋转导数的李代数近似;3)详细阐述高斯牛顿法的迭代流程,包括变换计算、最近邻搜索、参数更新等步骤;4)分析算法的优缺点,指出其具有二阶收敛速度但可能陷入局部最优。最后给出了完整的数学推导过程,包括误差函数的泰勒展开和目标函数的近似优化。该算法适用于三维点云配准任务,但需要良好的初始位姿以避免局部收敛问题

点云侠的博客 128

基于OpenClaw的自动化文件管理与文档分类系统设计与实现

本文介绍了一种基于OpenClaw的自动化文件管理与文档分类系统。系统采用三层架构设计,包含数据层、逻辑层和应用层,核心组件涵盖文件扫描、处理、分类、移动等功能。技术选型上使用Python/FastAPI作为后端,结合PostgreSQL/Elasticsearch/MinIO存储方案,并整合scikit-learn/PyTorch等AI技术实现智能分类。系统实现了文件递归扫描、增量扫描、元数据提取等功能,通过文件哈希和修改时间检测变化。该方案能有效提升文件管理效率,实现文档的自动化分类与智能管理。

一键难忘的博客 755

POJ2029——Get Many Persimmon Trees

Get Many Persimmon Trees Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3656   Accepted: 2378 Description Seiji Hayashi had been a professor of the Nisshinkan

Alex 1271

2024年11月架构设计师综合知识真题回顾,附参考答案、解析及所涉知识点(一)

软考高级考试包含三个科目:信息系统综合知识、系统架构设计案例分析和系统架构设计论文。考试形式为机考。本文主要回顾2024年下半年(2024-11-10)系统架构设计师考试上午综合知识科目的选择题,同时附带参考答案、解析和所涉知识点。由于机考时题目顺序是打乱的,本文题目所标序号只为区分不代表实际顺序。综合知识。

一几文的编程学习笔记。 9280

hdu3607——Traversal

Traversal Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1038    Accepted Submission(s): 365 Problem Description Xiao Ming is travelli

Alex 1270

手把手教你学Simulink——四开关 Buck‑Boost(FSBB)变换器的无缝模式切换仿真

本文详细介绍了四开关Buck-Boost(FSBB)变换器的Simulink仿真方法,重点解决模式切换时的直通风险和输出电压波动问题。通过统一电压PI控制、迟滞比较模式仲裁(Buck/Boost/Pass-Through)和200ns死区设计,实现了Vin从26V到22V变化时Vout稳定在12V±0.15V。关键步骤包括:搭建功率级电路、Stateflow模式判断、PI控制器输出占空比映射(Buck模式D≈Vo/Vin,Boost模式D≈1-Vo/Vin),以及带死区的PWM信号分配。仿真验证了切换过程中

MHD0815的博客 116

1分钟了解LangChain是什么?

是一个基于大型语言模型(LLM)开发应用程序的框架, 它旨在简化语言模型应用的开发流程,特别是在构建对话系统和其他基于语言的AI解决方案时.目标是将复杂的语言模型技术转化为可通过简单API调用实现的功能,从而使开发者能够更加专注于创造性的解决方案设计。高效地解决了开发大语言模型应用的痛点问题。Langchain 最主要的特色是可以将 LLM 应用研发过程中的交互 Prompt、LLM 模型调用、语言模型与环境互动的自适应等方式融为一体。

gorgor在码农 2630

hdu2275——Kiki & Little Kiki 1

Kiki & Little Kiki 1 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 873    Accepted Submission(s): 283 Problem Description Kiki is con

Alex 1257

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

POJ2492---A Bug's Life

A Bug's Life Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 29209   Accepted: 9528 Description Background Professor Hopper is researching the sexual behavio

Alex 1252

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

IMSL CNL 7.0.0 (x86-64)Crack

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

Codeforces Round #170 (Div. 2)---C. Learning Languages(并查集)

The “BerCorp” company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee w

Alex 1238

STM32F407中文手册

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

Codeforces Round #172 (Div. 2)---D. Maximum Xor Secondary(RMQ + 二分)

Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, …, xk (k > 1) is such maximum element xj, that the following in

Alex 1222

sdut2610---Boring Counting(离线+树状数组+离散化)

Boring Counting Time Limit: 3000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 In this problem you are given a number sequence P consisting of N integer and Pi is the ith element in the sequence. No

Alex 1187

hdu4719——Oh My Holy FFF

Oh My Holy FFF Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 626    Accepted Submission(s): 147 Problem Description N soldiers from t

Alex 1163

POJ1177----Picture

Picture Time Limit: 2000MS   Memory Limit: 10000K Total Submissions: 10727   Accepted: 5662 Description A number of rectangular posters, photographs and other pictures of t

Alex 1125

Codeforces Round #225 (Div. 2)---E. Propagating tree(时间戳+线段树)

Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of n nodes numbered from 1 to n, each node i having an initial value ai. The root of th

Alex 1123

Codeforces Beta Round #75 (Div. 1 Only)---B.Queue

There are n walruses standing in a queue in an airport. They are numbered starting from the queue’s tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of t

Alex 1120

hdu3911---Black And White

Black And White Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3971 Accepted Submission(s): 1183Problem Description There are a bunch of

Alex 1093
上一篇: NOJ1553---Beautiful Walls(尺取法)
下一篇: hdu4691---Front compression(后缀数组+RMQ)
tokers
博客等级 码龄12年 71粉丝 700原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值