徐州赛区网络赛 Ryuji doesn't want to study 线段树维护区间和

数字IC后端实现 | Innovus各个阶段常用命令汇总 数字IC后端设计实现之Innovus常用命令汇总 阅读详情

题目链接:https://nanti.jisuanke.com/t/31460

Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i].

Unfortunately, the longer he learns, the fewer he gets.

That means, if he reads books from ll to rr, he will get a[l] \times L + a[l+1] \times (L-1) + \cdots + a[r-1] \times 2 + a[r]a[l]×L+a[l+1]×(L−1)+⋯+a[r−1]×2+a[r](LL is the length of [ ll, rr ] that equals to r - l + 1r−l+1).

Now Ryuji has qq questions, you should answer him:

11. If the question type is 11, you should answer how much knowledge he will get after he reads books [ ll, rr ].

22. If the question type is 22, Ryuji will change the ith book's knowledge to a new value.

Input

First line contains two integers nn and qq (nn, q \le 100000q≤100000).

The next line contains n integers represent a[i]( a[i] \le 1e9)a[i](a[i]≤1e9) .

Then in next qq line each line contains three integers aa, bb, cc, if a = 1a=1, it means question type is 11, and bb, cc represents [ ll , rr ]. if a = 2a=2 , it means question type is 22 , and bb, cc means Ryuji changes the bth book' knowledge to cc

Output

For each question, output one line with one integer represent the answer.

样例输入复制

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

样例输出复制

10
8

要计算题目里类似卷积一样的东西,可以把原数组变成a[i]*=(n-i+1)然后建线段树维护区间和,记为p1(l,r)

再保持数组原样不变,单独维护区间和,记为p2(l,r)

1操作时,直接输出p1(l,r)-p2(l,r)*(n-r+1)

2操作时,更新两个前缀和

#include<bits/stdc++.h>
#include<math.h>
#define MOD  1000000007
#define For(i,m,n) for(int i=m;i<=n;i++)
#define LL long long
#define inf 0x3f3f3f3f
#define lan(a,b) memset(a,b,sizeof(a))
#define sqr(x) (x*x)
using namespace std;

#define maxn 100010



struct node
{
    int l,r;
    LL k;//标记值
    LL m;//存储值
};

node tree[2][maxn*4];
LL a[2][maxn];

void build(int n ,int l,int r,int t)
{
    tree[t][n].l=l;
    tree[t][n].r=r;
    if(l==r)
    {

        tree[t][n].m=a[t][l];//////////////////////////视情况
        return;
    }
    int mid=(l+r)/2;
    build(n<<1,l,mid,t);
    build(n<<1|1,mid+1,r,t);
    tree[t][n].m=tree[t][n<<1].m+tree[t][n<<1|1].m;/////////////////////看线段树种类
}

void pushup(int n,int t)
{
    tree[t][n].m=tree[t][n<<1].m+tree[t][n<<1|1].m;////////////////////看线段树种类
}

void update(int n,int l,int r,LL c,int t)
{
    if(tree[t][n].l==l&&tree[t][n].r==r)
    {
        tree[t][n].m=c;
        return;
    }
    int mid=(tree[t][n].r+tree[t][n].l)/2;
    if(r<=mid)
        update(n<<1,l,r,c,t);
    else if(l>=mid+1)
        update(n<<1|1,l,r,c,t);
    else
    {
        update(n<<1,l,mid,c,t);
        update(n<<1|1,mid+1,r,c,t);
    }
    pushup(n,t);
}

LL query(int n,int l,int r,int t)
{
    if(tree[t][n].l==l&&tree[t][n].r==r)
    {
        return tree[t][n].m;
    }
    int mid=(tree[t][n].r+tree[t][n].l)/2;

    LL res=0;
    if(r<=mid)
        res+=query(n<<1,l,r,t);
    else if(l>=mid+1)
        res+=query(n<<1|1,l,r,t);
    else
    {
        res+=query(n<<1,l,mid,t);////////////////////看线段树种类
        res+=query(n<<1|1,mid+1,r,t);////////////////////看线段树种类
    }
    return res;
}

int main()
{
    LL n,q;
    while(~scanf("%lld%lld",&n,&q))
    {
        lan(tree,0);
        lan(a,0);
        For(i,1,n)
            scanf("%lld",&a[0][i]),a[1][i]=a[0][i];
        build(1,1,n,1);
        LL tem=n;
        For(i,1,n)
        {
            a[0][i]*=tem;
            tem--;
//            printf("a%d=%lld\n",i,a[0][i]);
        }
        build(1,1,n,0);
        while(q--)
        {
            LL op,l,r;
            scanf("%lld%lld%lld",&op,&l,&r);
            if(op==1)
            {
                LL ans=0;
                ans=query(1,l,r,0)-query(1,l,r,1)*(n-r);
//                printf("%lld %lld %lld\n",query(1,l,r,0),query(1,l,r,1),n-r);
                printf("%lld\n",ans);
            }
            else
            {
                update(1,l,l,r*(n-l+1),0);
                update(1,l,l,r,1);
            }
        }
    }
    return 0;
}

 

Qt入门教程100篇(已完结) Qt5入门教程,Qt6入门教程。包含了: Qt环境搭建篇、Qt数据类型篇、Qt中STL篇、Qt核心篇、Qt核心对象QObject篇、Qt基础控件篇、Qt对话框篇、Qt高级控件篇、Qt数据模型篇、QSS篇、Qt文件篇 、Qt硬件编程、Qt的一些demo、Qt项目开发篇。...... 阅读详情

相关推荐

Postman调试海康ISAPI接口全记录:从鉴权失败到成功修改设备名的踩坑指南

本文详细记录了使用Postman调试海康ISAPI接口的全过程,从鉴权失败到成功修改设备名的实战经验。涵盖Digest认证机制、XML请求体构造、常见错误排查及代码实现过渡,帮助开发者高效解决海康设备集成中的各种问题。

weixin_42620913的博客 660

Ryuji doesn't want to study(线段树)

Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i]. Unfortunately, the longer he learns, the fewer he gets. That m...

qq_37378303的博客 276

《跨界杂谈》华为印象(五):高度集权的矩阵式架构

高度集权的矩阵式架构 “高度集权的矩阵式架构”不是官方术语。是笔者的一位同事非常经典的总结。解释这个句话还是有点困难的,笔者入职华为三年也没彻底搞明白,在这里只能尝试性的解释一下。 矩阵 我们先看一下“矩阵”。华为有两套部门职能体系,华为内部术语,叫实线部门和虚线部门。由实线与虚线部门交叉构成矩阵。大部分(但不是所有)华为员工都由两个部门(两个领导)进行管理。对员工而言,所谓的实线部

《云计算架构技术与实践》 2994

【计蒜客】2018ICPC徐州赛区网络赛H Ryuji doesn't want to study(树状数组)

题目链接   【题意】 Ryuji不想学习,但他会学习一段时间,但是每天的学习效率会下降,其实题目说了一堆就是一个式子。 [r,l]是Ryuji学习时间的一个区间,然后有q次查询,当a=1时,查询l-r的总知识量,当a=2时,更新第l本书的知识量为r。   【解题思路】 将上述式子化简后可得 所以只需要用树状数组或线段树维护a[i]和a[i]*(n-i+1)这两个前缀和...

よろしくお願いします 420

深信服PT1-AF实验考试

深信服PT1-AF实验考试实验练习可以去深信服的在线实验平台(链接如下):深信服在线实验平台 (sangfor.com.cn)实验考试其实就是把所有的每一部分实验综合了起来以下内容仅做参考,不确保一样。

m0_72019240的博客 7106

Grafana图像渲染插件安装全攻略:解决依赖缺失问题(附完整命令清单)

本文详细介绍了在CentOS/RHEL环境下安装Grafana图像渲染插件`grafana-image-renderer`的全过程,包括解决常见的依赖缺失问题。通过提供完整的命令清单和疑难问题排查指南,帮助用户高效部署和优化插件性能,确保图像渲染功能稳定运行。

weixin_30399821的博客 85

徐州网络赛H-Ryuji doesn't want to study【线段树】

Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i]. Unfortunately, the longer he learns, the fewer he gets. That m...

wybooooooooo的博客 270

Dynamics 365 On-Premise Server v9.0部署体验

期盼已久的Dynamics 365 On-Premise的版本升级终于在11月初姗姗来迟。 11月2日起已经可以在官方渠道下载正式版的Dynamics 365 Server v9.0安装文件,版本号9.0.2,随手附上中文版安装文件下载地址。 想必已经有不少小伙伴开始尝试各种升级、安装了吧。 Dynamics 365 On-Premise的安装过程,度娘一下已经有很多了,这里就不赘述了,只是...

Roger的专栏 2138

2018徐州模拟赛-H-Ryuji doesn't want to study

 1000ms  262144K Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i]. Unfortunately, the longer he learns, the fewe...

han_hhh的博客 388

使用C++实现DNS欺骗攻击

其中,domain_name表示需要欺骗的域名,dns_server_ip表示实际DNS服务器的IP地址,fake_ip表示需要重定向到的IP地址。在DNS查询过程中,当客户端向DNS服务器请求解析某个域名时,DNS服务器会返回该域名对应的IP地址。DNS劫持是一种常见的网络攻击方式,通过篡改DNS响应数据,使得用户访问的网站被重定向到攻击者指定的恶意站点。我们使用C++编写一个简单的DNS欺骗程序,使得当客户端请求解析特定的域名时,我们可以将其重定向到指定的IP地址。使用C++实现DNS欺骗攻击。

TechGlide的博客 411

进阶06:C#连接TwinCAT 3使用ADS通讯

本文介绍了使用C#通过ADS协议与倍福TwinCAT3 PLC通讯的实现方法。主要内容包括:1)在两台电脑上安装TwinCAT3开发环境并建立网络连接;2)在TwinCAT中定义变量和结构体;3)使用C# Winform开发界面,通过TwinCAT.Ads.dll实现读写功能;4)实现主动读取和通知两种数据获取方式。详细说明了连接建立、变量定义、读写操作及事件通知的实现代码。该方案实现了对PLC寄存器数据的实时监控和操作,为工业控制系统的开发提供了参考。

weixin_38637405的博客 3688

徐州赛区网络赛 Ryuji doesn't want to study(树状数组)

Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i]. Unfortunately, the longer he learns, the fewer he gets. That m...

柳予欣的三味书屋~ 373

向华为学习——IPD流程体系之IPD术语

《IPD体系核心概念与业务术语解析》摘要: IPD(集成产品开发)是一种以市场为导向的结构化产品开发管理模式,通过跨部门协作、异步开发、CBB(通用构建模块)和管道管理等手段,实现产品全生命周期高效管理。体系包含七大核心要素:跨部门团队(如IPMT决策层、PDT执行层)、结构化流程(分阶段评审)、端到端项目管理(WBS分级计划)、客户需求分析、投资组合优化及质量管控(TR技术评审)。各业务领域术语涵盖财务(NPV、IRR)、开发(需求分解、基线化)、制造(可制造性设计)、采购(Sourcing团队)及市场(

cdfunlove的博客 481

(线段树维护前缀和)Ryuji doesn't want to study

Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i]. Unfortunately, the longer he learns, the fewer he gets. That m...

black_horse2018的博客 620

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn’t want to study 线段树+带权查询

ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn’t want to study 标签 线段树 带权查询 简明题意 给一个序列,需要支持两种操作: 查询:查询L-R区间,a[l]×L+a[l+1]×(L−1)+⋯+a[r−1]×2+a[r]a[l]×L+a[l+1]×(L−1)+⋯+a[r−1]×2+a[r]a[l]×L+a[l+1]×(L−1)+⋯+a[r...

danzh 140

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

ACM-ICPC 2018 徐州赛区网络预赛.H--Ryuji doesn't want to study.(线段树维护前缀和)

Ryuji is not a good student, and he doesn’t want to study. But there are n books he should learn, each book has its knowledge a[i]a[i]. Unfortunately, the longer he learns, the fewer he gets. That mea...

qq_44238714的博客 120

pscad IEEE标准系统搭建说明

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

ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study (线段树维护前缀和的前缀和)

题意 很简答就是每次查询 (L,R)的时候 ,查询 a[L]∗(R−L+1)+a[L+1]∗(R−L−1)+a[L+2]∗(R−L−2)....a[R]∗1a[L]∗(R−L+1)+a[L+1]∗(R−L−1)+a[L+2]∗(R−L−2)....a[R]∗1a[L] * (R-L+1) + a[L+1] *(R-L-1) + a[L+2] * (R-L-2)....a[R]*1,还有修改值 ...

wjmwsgj的博客 254

ACM-ICPC 2018徐州赛区网络预赛 H.Ryuji doesn't want to study(线段树)

题目 n个数,q个操作(n,q<=1e5) 操作分两种, 1 l r 询问[l,r]区间内,的值 2 x y 把a[x]的值改成y 思路来源 凯神 题解 结构体维护三个值 sum:这一段的和 ans:这一段的答案 num:这一段的数字的个数 与合并的时候 sum和num可以直接合并, 而这一段的ans 心得 还是结构体的比较常用吖 配合函数传参这...

小衣同学的博客 191

ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn‘t want to study (线段树+思维)

Ryuji doesn’t want to study 这个题挺有意思的 两棵线段树 一棵维护的是数组 另一棵维护的是数组每一项乘以它的倒着的位数 如下图: 一棵维护的是矩形 另一颗维护的是大的三角形 AC code /* Ryuji doesn't want to study ACM-ICPC 2018 徐州赛区网络预赛 H. https://nanti.jisuanke.com/t/A200...

weixin_44410512的博客 199

ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study(线段树)

线段树模式的题目,两个操作 1,l,r 查询a[l]*Len + a[l+1]*(Len-1) … + a[r]这个结果 2.p,v,把p位置更新为v 比赛时很早就发现这个题目可以做了。 而且自己也写过类似的题目,但时不知道为何自己比赛的时候就是不能一次的通过,队友对自己代码的不信任大概也都时来自与此吧,毕竟谁愿意相信一个经常写WA的人来去写呢。 该线段树维护一个区间和以及一个区间值(查...

henuzxy 551

ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study —— 线段树lazy标记区间修改

博客目录 原题   传送门  1000ms  262144K Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i]. Unfortunately, the longer h...

GreyBtfly的博客 565

ACM-ICPC 2018 徐州赛区网络预赛 徐州 H Ryuji doesn't want to study 线段树

Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i]a[i]. Unfortunately, the longer he learns, the fewer he gets. Th...

zamaochick的博客 360

ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study [ 线段树 ]

题目链接: ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study 题意概括: 对于一个序列,查询操作是给出一个区间[l, r],求 还有单点修改序列的操作 数据范围: 题解分析: 频繁的区间询问、区间修改,很明显就是线段树的题了 对每个节点,维护三个变量 sum : 存储该序列区间所有值的和 ans : 存储该序...

Originum的博客 407

计蒜客 Ryuji doesn't want to study(2018 ICPC 徐州 网络赛 )线段树

Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i]. Unfortunately, the longer he learns, the fewer he gets. That m...

LinzhiQQQ的博客 298

计蒜客 Ryuji doesn't want to study(2018 ICPC亚洲区域赛网络赛 徐州 H)(线段树)

Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i]. Unfortunately, the longer he learns, the fewer he gets. That m...

LP_Cong 414

ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study

Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i]. Unfortunately, the longer he learns, the fewer he gets. That m...

gtuif的博客 256
上一篇: hdu 6053 TrickGCD 反演
下一篇: 计蒜客南京赛区预选赛 skr 回文树
Dale_zero
博客等级 码龄9年 10粉丝 174原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值