徐州H
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define ms(arr,a) memset(arr,a,sizeof arr)
#define debug(x) cout<<"< "#x" = "<<x<<" >"<<endl
const int maxF=1e5+5;
int n,q;
long long s[maxF],ss[maxF];
inline lowbit(int x)
{
return x&(-x);
}
void adds(int i,long long k)
{
while(i<=n)
{
s[i]+=k;
i+=lowbit(i);
}
}
void addss(int i,long long k)
{
while(i<=n)
{
ss[i]+=k;
i+=lowbit(i);
}
}
long long sums(int i)
{
long long ret=0;
while(i)
{
ret+=s[i];
i-=lowbit(i);
}
return ret;
}
long long sumss(int i)
{
long long ret=0;
while(i)
{
ret+=ss[i];
i-=lowbit(i);
}
return ret;
}
int main()
{
//freopen("Input.txt","r",stdin);
//freopen("Output.txt","w",stdout);
while(~scanf("%d%d",&n,&q))
{
long long tmp;
for(int i=1;i<=n;++i)
{
scanf("%lld",&tmp);
adds(i,tmp);addss(i,tmp*i);
}
int a,b,c;
for(int i=1;i<=q;++i)
{
scanf("%d%d%d",&a,&b,&c);
if(a==1)
{
printf("%lld\n",1LL*(c+1)*(sums(c)-sums(b-1))-sumss(c)+sumss(b-1));
}
else{
long long tmp=sums(b)-sums(b-1);
adds(b,1LL*c-tmp);addss(b,1LL*b*c-tmp*b);
}
}
}
//freopen("CON","w",stdout);
//system("start Output.txt");
}
徐州H的更多相关文章
- 2018网络预选赛 徐州H 线段树+树状数组
设读入的数组是a,树状数组用来维护a数组区间和sum,线段树用来维护一个另一个数组ssum的区间和,区间每个点a[i]*(n-i+1),那么l-r的答案是l-r的ssum-(n-r)*(sum[r]- ...
- 2018icpc 徐州h题
题目大意: https://codeforces.com/gym/102012/problem/H?csrf_token=c9d0191a64a241166d54a565b1615125 区间[l , ...
- 计蒜客 1460.Ryuji doesn't want to study-树状数组 or 线段树 (ACM-ICPC 2018 徐州赛区网络预赛 H)
H.Ryuji doesn't want to study 27.34% 1000ms 262144K Ryuji is not a good student, and he doesn't wa ...
- 2019~2020icpc亚洲区域赛徐州站H. Yuuki and a problem
2019~2020icpc亚洲区域赛徐州站H. Yuuki and a problem 题意: 给定一个长度为\(n\)的序列,有两种操作: 1:单点修改. 2:查询区间\([L,R]\)范围内所有子 ...
- ACM-ICPC 2018 徐州赛区网络预赛 H Ryuji doesn't want to study (树状数组差分)
https://nanti.jisuanke.com/t/31460 题意 两个操作.1:查询区间[l,r]的和,设长度为L=r-l+1, sum=a[l]*L+a[l+1]*(L-1)+...+a[ ...
- 计蒜客 31460 - Ryuji doesn't want to study - [线段树][2018ICPC徐州网络预赛H题]
题目链接:https://nanti.jisuanke.com/t/31460 Ryuji is not a good student, and he doesn't want to study. B ...
- 2018徐州网络赛H. Ryuji doesn't want to study
题目链接: https://nanti.jisuanke.com/t/31458 题解: 建立两个树状数组,第一个是,a[1]*n+a[2]*(n-1)....+a[n]*1;第二个是正常的a[1], ...
- ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study
262144K Ryuji is not a good student, and he doesn't want to study. But there are n books he should ...
- 2019徐州网络赛 H.function
题意: 先有\(n=p_1^{k_1}p_2^{k_2}\cdots p_m^{k_m}\),定义\(f(n)=k_1+k_2+\cdots+k_m\). 现在计算 \[ \sum_{i=1}^nf( ...
随机推荐
- C - Can you solve this equation? HDU - 2199(二分水题)
Now,given the equation 8x^4 + 7x^3 + 2x^2 + 3x + 6 == Y,can you find its solution between 0 and 100; ...
- Q - Queue HDU - 5493(树状树组维护区间前缀和 + 二分找预留空位)
Q - Queue HDU - 5493 Problem Description NNN people numbered from 1 to NNN are waiting in a bank for ...
- canvas 悬浮效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- PTA | 1056 组合数的和 (15分)
给定 N 个非 0 的个位数字,用其中任意 2 个数字都可以组合成 1 个 2 位的数字.要求所有可能组合出来的 2 位数字的和.例如给定 2.5.8,则可以组合出:25.28.52.58.82.85 ...
- Linux服务器架设篇,DNS服务器(一),基础知识
一.端口 DNS监听端口 注意: DNS通常是以UDP协议来进行数据传输协议的,但是若没有办法查询到完整的信息是.DNS的daemon是named,它会启动TCP和UDP的53端口,所以启用DSN服务 ...
- 开源运动的"圣经"——《大教堂与集市》读书笔记
作者:Eric S. Raymond 一.黑客圈简史 1.早期 (1)MIT 与 ITS "黑客"一词大约就起源于MIT的计算机文化. 从PDP-1时代开始,黑客文化的命运就和DE ...
- Thinking in Java,Fourth Edition(Java 编程思想,第四版)学习笔记(二)之Introduction to Objects
The genesis of the computer revolution was a machine. The genesis of out programming languages thus ...
- 一些SpringBoot的初步理解
SpringBoot SpringBoot作为近几年很火的微服务框架,只需要简单的几个依赖,少量的配置,就可以使用它快速搭建一个轻量级的微服务,优点是简单.快速.大道至简,缺点是真的太单一,不适于项目 ...
- PDF阅读器
1.SumatraPDF 非常小巧,打开很轻快 2.PDF Reader by Xodo window商店中可以找到,很好用 3. PDFXChange Editor这是我迄今为止见过的最好的PDF编 ...
- python 3 的解释器
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:Yangtze PS:如有需要Python学习资料的小伙伴可以加点击下 ...