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 equals to r - l + 1),或者 2 i b:把第i个换成b
思路:用一个树状数组存i的前缀和,再用一个树状数组存(n - i + 1)*a[ i ]的前缀和,这样算出后面那个的区间差减去前一个的区间差的某个倍数就会成为答案。
代码:
#include<queue>
#include<cstring>
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<vector>
#include<cstdio>
#include<iostream>
#include<algorithm>
typedef long long ll;
const int maxn = + ;
const int seed = ;
const ll MOD = 1e9 + ;
const int INF = 0x3f3f3f3f;
using namespace std;
ll sum[][maxn], a[maxn];
ll n;
int lowbit(int x){
return x&(-x);
}
void update(int x, ll v, int id){
for(int i = x; i <= n; i += lowbit(i)){
sum[id][i] += v;
}
}
ll query(int x, int id){
ll cnt = ;
for(int i = x; i > ; i -= lowbit(i)){
cnt += sum[id][i];
}
return cnt;
}
int main(){
ll q;
while(~scanf("%lld%lld", &n, &q)){
memset(sum, , sizeof(sum));
for(int i = ; i <= n; i++){
scanf("%lld", &a[i]);
update(i, a[i], );
update(i, a[i] * (n - i + ), );
}
while(q--){
ll u, v, w;
scanf("%lld%lld%lld", &u, &v, &w);
if(u == ){
printf("%lld\n", query(w, ) - query(v - , ) - (n - w) * (query(w, ) - query(v - , )));
}
else{
update(v, -a[v] + w, );
update(v, (-a[v] + w) * (n - v + ), );
a[v] = w;
}
}
}
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
262144K Ryuji is not a good student, and he doesn't want to study. But there are n books he should ...
- 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(树状数组)
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 徐州赛区网络预赛 G Trace(逆向,两颗线段树写法)
https://nanti.jisuanke.com/t/31459 思路 凡是后面的轨迹对前面的轨迹有影响的,可以尝试从后往前扫 区间修改需要push_down,单点更新所以不需要push_up(用 ...
- 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 ...
随机推荐
- QS Network---zoj1586最小生成树
Description Sunny Cup 2003 - Preliminary Round April 20th, 12:00 - 17:00 Problem E: QS Network In th ...
- CSS的未来:一些试验性CSS属性
尽管现代浏览器已经支持了众多的CSS3属性,但是大部分设计师和开发人员貌似依然在关注于一些很“主流”的属性,如border-radius.box-shadow或者transform等.它们有良好的文档 ...
- memcached-session-manager 教程实现session共享
1简单介绍 1.1决定用什么序列化策略. 1.2配置tomcat 1.2.1加入 memcached-session-manager jar 包到tomcat中. ...
- MyEclipse10.0 注册破解步骤
MyEclipse 10.0破解 激活(java编写,适用于装有java环境的各种操作系统,Windows,Linux,MacOS) =====[方法一]=====[第一步]:输入任意用户名[第二步] ...
- java maven项目找不到jconsole-1.8.0.jar和tools-1.8.0.jar包
今天在整合jar包时候,出现了 这是我导入的jar坐标 <dependency> <groupId>com.alibaba</groupId> <artifa ...
- R中双表操作学习[转载]
转自:https://www.jianshu.com/p/a7af4f6e50c3 1.原始数据 以上是原有的一个,再生成一个新的: > gene_exp_tidy2 <- data.fr ...
- JavaScrip总体
js: 简单对象: 数字 | 字符串 | 这三个像对象,有方法,但不可变 布尔值 | null undefined 对象:无类型,k-v对集合:函数.数组.REG.... JavaScript是一种l ...
- IDA 7.0在Mojava更新后打不开的问题
Mac升级到mojava后,ida 7.0打不开了. 上述是两种典型的窗口,不过不论是出现什么样的弹窗,如果是在升级之后出现的,都要试一下下面的解决办法.因为IDA7.0版本流出的比较多,虽然这个已经 ...
- LeetCode--Two_Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- iOS 新浪微博-1.0框架搭建
项目搭建 1.新建一个微博的项目,去掉屏幕旋转 2.设置屏幕方向-->只有竖向 3.使用代码构建UI,不使用storyboard 4.配置图标AppIcon和LaunchImage 将微博资料的 ...