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 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] * L + a[l+1] *(L-1) + …… + a[r-1] *2 + a[r](L is the length of [ l, r ] that equals to r−l+1).
Now Ryuji has qq questions, you should answer him:
1. If the question type is 1, you should answer how much knowledge he will get after he reads books [ l, r ].
2. If the question type is 2, Ryuji will change the ith book's knowledge to a new value.
Input
First line contains two integers nn and qq (n, q≤100000).
The next line contains n integers represent a[i](a[i]≤1e9) .
Then in next qq line each line contains three integers a, b, c, if a = 1, it means question type is 1, and b, ccrepresents [ l, r ]. if a =2 , it means question type is 2 , 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
题目来源
#define ull unsigned long long
#define ll long long
#define N 100009
#define lowbit(x) x&(-x)
ull c1[N],c2[N];
int n,q;
void update1(int x,ull num)
{
while(x<=n)
{
c1[x]+=num;
x+=lowbit(x);
}
}
ull getsum1(int x)
{
ull sum=;
while(x>)
{
sum+=c1[x];
x-=lowbit(x);
}
return sum;
}
void update2(int x,ull num)
{
while(x<=n)
{
c2[x]+=num;
x+=lowbit(x);
}
}
ull getsum2(int x)
{
ull sum=;
while(x>)
{
sum+=c2[x];
x-=lowbit(x);
}
return sum;
}
int main()
{
scanf("%d%d",&n,&q);
ull x;
for(int i=;i<=n;i++)
{
scanf("%lld",&x);
update1(i,x);
update2(i,1ull*(n-i+)*x);//在前面加个 ull 保证整体是ull 的
}
int op,l,r;
while(q--)
{
scanf("%d%d%d",&op,&l,&r);
if(op==)
{
ull ans1=1ull*(n-r)*(getsum1(r)-getsum1(l-));
ull ans2=getsum2(r)-getsum2(l-);
printf("%lld\n",ans2-ans1);//"u" 是unsigned int
}
else{
ull temp=getsum1(l)-getsum1(l-);
update1(l,1ull*(r-temp) );
update2(l,1ull*(r-temp)*(n-l+)) ;
}
}
return ;
}
ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study的更多相关文章
- 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[ ...
- 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, ea ...
- ACM-ICPC 2018 徐州赛区网络预赛H Ryuji doesn't want to study(树状数组)题解
题意:给你数组a,有两个操作 1 l r,计算l到r的答案:a[l]×L+a[l+1]×(L−1)+⋯+a[r−1]×2+a[r] (L is the length of [ l, r ] that ...
- ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study(树状数组)
Output For each question, output one line with one integer represent the answer. 样例输入 5 3 1 2 3 4 5 ...
- 计蒜客 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 ...
- ACM-ICPC 2018 徐州赛区网络预赛 B(dp || 博弈(未完成)
传送门 题面: In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl n ...
- ACM-ICPC 2018 徐州赛区网络预赛 D 杜教筛 前缀和
链接 https://nanti.jisuanke.com/t/31456 参考题解 https://blog.csdn.net/ftx456789/article/details/82590044 ...
- ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)
ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...
- ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer (最大生成树+LCA求节点距离)
ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer J. Maze Designer After the long vacation, the maze designer ...
随机推荐
- 公司项目git开发流程规范
手动修改冲突之后,git add . git commit ,git push
- 去除inline-block间隙的几种方法
为什么会产生间隙? 由于编写代码时的美观和可读性,在代码中添加回车或空格而产生的间隙. html代码: <ul class="container"> <li> ...
- zblog去除底部版权信息 “请勿修改或删除主题版权及作者信息”
场景:使用了免费模板,但底部带作者版权.删除版权信息的代码后访问前台弹窗:请勿修改或删除主题版权及作者信息... 1. 删除版权信息代码 使用notepad++搜索功能,搜索版权信息:如ABC,找到相 ...
- Vmware 虚拟硬盘 合并多个分割文件
有时,当我们创建虚拟机vmware里面的应用程序,我们可能会选择创建分割的虚拟磁盘中的多个文件2 GB的文件,这是为了提高复制过程,主要用于存储虚拟机文件系统不支持创建更大的文件. 如果我们需要将它转 ...
- Java多线程常见问题
1. 进程和线程之间有什么不同? 一个进程是一个独立(self contained)的运行环境,它可以被看作一个程序或者一个应用.而线程是在进程中执行的一个任务.Java运行环境是一个包含了不同的类和 ...
- OSSIM安装与使用感受
下载地址 http://www.alienvault.com OSSIM通过将开源产品进行集成,从而提供一种能够实现安全监控功能的基础平台.它的目标是提供一种集中式.有组织的,能够更好地进行监测和显示 ...
- Netbackup8.0以上版本,服务端生成证书,客户端获取、更新证书方式(整理中)
创建重发令牌 如果非主控主机已在主服务器上注册但其基于主机ID的证书不再有效,则可以重新颁发基于主机ID的证书.例如,证书在过期,被撤销或丢失时无效. 重发令牌是一种可用于重新颁发证书的令牌.它是一种 ...
- sklearn 学习之分类树
概要 基于 sklearn 包自带的 iris 数据集,了解一下分类树的各种参数设置以及代表的意义. iris 数据集介绍 iris 数据集包含 150 个样本,对应数据集的每行数据,每行数据包含 ...
- Where art thou-freecodecamp算法题目
Where art thou 1.要求 写一个 function,它遍历一个对象数组(第一个参数)并返回一个包含相匹配的属性-值对(第二个参数)的所有对象的数组. 如果返回的数组中包含 source ...
- C++ 学习笔记(二) const的加强
const 含义为只读.如果在程序中显式改变const变量那么编译会报错. C语言的const: 在C语言中const 变量是放在内存中,如果使用指针可以间接改变const变量.所以在C语言中cons ...