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 ...
随机推荐
- SSH 的端口转发
第一部分 概述 当你在咖啡馆享受免费 WiFi 的时候,有没有想到可能有人正在窃取你的密码及隐私信息?当你发现实验室的防火墙阻止了你的网络应用端口,是不是有苦难言?来看看 SSH 的端口转发功能能给我 ...
- 终于有人把P2P、P2C、O2O、B2C、B2B、C2C的区别讲透了!还有许多其它类别的类型分享
平时在看招聘时,经常看到我们是什么B2C电子商务网站,但是一直不知是啥意思,今天在WEB开发者上面看到这篇文章,就是知道了个所以然,以记录分享. P2P.P2C .O2O .B2C.B2B. C2C, ...
- hive中select中DISTINCT的技巧和使用
hive中select中DISTINCT的技巧和使用 单表的唯一查询用:distinct 多表的唯一查询用:group by 在使用MySQL时,有时需要查询出某个字段不重复的记录,虽然mysql提供 ...
- .Net平台互操作技术:02. 技术介绍
上一篇文章简单介绍了.Net平台互操作技术的面临的主要问题,以及主要的解决方案.本文将重点介绍使用相对较多的P/Invoke技术的实现:C#通过P/Invoke调用Native C++ Dll技术.C ...
- 关于学习Lisp的一点思考
以前读<黑客与画家>,其中对Lisp语言的赞美和推崇,让我燃起学习Lisp语言的强烈冲动,但很快发现在实际工作中应用的场景很少,出于功利心最终放弃了.直到上周未在家里读完了<大教堂与 ...
- Linux Shell流程例子
#!/bin/bash read -p "input a dight:"echo $REPLY DATE=`date`echo "DATE is ${DATE}" ...
- C#中静态成员和实例变量
昨天晚上看静态成员和实例变量的时候,看到这样的一句话:默认情况下,若成员被定义为实例变量,这就意味着类需要为每个实例都建立一个副本,而在定义一个静态变量的时候,只存在此成员的一个副本. 呵呵,今天跟前 ...
- [nmon]使用nmon工具监控系统资源
1.下载nmon 下载正确的nmon版本, 查看linux服务器版本,命令:lsb_release -a,查看到当前系统为RedHat 6.4 然后我们根据我们的linux版本,下载相应nmon版本, ...
- 洛谷 P2380 狗哥采矿
题目背景 又是一节平静的语文课 狗哥闲来无事,出来了这么一道题 题目描述 一个n*m的矩阵中,每个格子内有两种矿yeyenum和bloggium,并且知道它们在每个格子内的数量是多少.最北边有blog ...
- 使用代码获得Netweaver里某个software component和C4C的版本
有同事问如何通过代码的方式获得Netweaver里某个Software component的版本信息,以及Cloud for Customer(C4C)的版本信息. Netweaver 点了Detai ...