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
1 1 3
2 5 0
1 4 5
样例输出
10
8
两个树状数组一个维护a[i]前缀合,一个维护(n-i+1)*a[i]前缀和。
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define esp 1e-9
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
typedef unsigned long long ll;
ll sum[],n,m;
ll pos[];
ll a[];
void add(int x,ll val){
for(int i=x;i;i-=lowbit(i))
sum[i]+=val;
}
ll query(int x){
ll ans=;
for(int i=x;i<=;i+=lowbit(i))
ans+=sum[i];
return ans;
}
void add_one(int x,ll val){
for(int i=x;i;i-=lowbit(i))
pos[i]+=val;
}
ll query_one(int x){
ll ans=;
for(int i=x;i<=;i+=lowbit(i))
ans+=pos[i];
return ans;
}
int main()
{
while(scanf("%lld%lld",&n,&m)!=EOF)
{
memset(sum,,sizeof(sum));
memset(pos,,sizeof(pos));
memset(a,,sizeof(a));
for(int i=;i<=n;i++)
{
scanf("%lld",&a[i]);
add(i,1ll*a[i]*(n-i+));
add_one(i,a[i]);
}
while(m--){
ll op,x,y;
scanf("%lld%lld%lld",&op,&x,&y);
if(op==)
{
ll l=query(x);
ll r=query(y+);
ll u=query_one(x);
ll d=query_one(y+);
//printf("%lld\n",u-d);
printf("%lld\n",l-r-(1ll*(n-y)*(u-d)));
}
else{
add(x,1ll*(-)*a[x]*(n-x+));
add(x,1ll*(n-x+)*y);
add_one(x,1ll*(-)*a[x]);
a[x]=y;
add_one(x,1ll*a[x]);
}
}
}
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(树状数组)题解
题意:给你数组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 ...
- 计蒜客 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 ...
随机推荐
- es6总结(二)
1.es6三种声明方式: a.var 全局声明 b.let 局部变量声明 c.const 常量声明 2.变量的解构赋值 a.数组的解构赋值 等号左边与右边形式统一 let [a,[b,c] ...
- FrameLsyout
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_ ...
- Android开发中:小米2S DDMS 不显示
参考:http://bbs.xiaomi.cn/thread-5672159-1-1.html
- day13 基本的文件操作(好东西)
目录 基本的文件处理 什么是文件 如何使用文件 使用Python写一个小程序控制文件 open(打开文件) read: readline:一次性读取一行 del:删除 close:关闭 write(写 ...
- 从0实现一个React,个人总结
原文: https://github.com/hujiulong/blog/issues/4 个人总结:: 一.JSX和虚拟DOM import React from 'react'; import ...
- Mysql干货收集
mysql优化:https://www.cnblogs.com/duanxz/tag/mysql/default.html?page=1
- 使用Storyboard实现复杂界面
http://blog.csdn.net/guchengluoye/article/details/7472771 http://wangjun.easymorse.com/?p=1564 http: ...
- 2019-03-20 Python爬取需要登录的有验证码的网站
当你向验证码发起请求的时候,就有session了,记录下这次session 因为每当你请求一次验证码 或者 请求一次登录首页,验证码都在变动 验证码的链接可能不是固定的,可能需要GET/POST请求, ...
- poj 2663 Tri Tiling (状压dp+多米诺骨牌问题+滚动数组反思)
本来直接一波状压dpAC的 #include<cstdio> #include<cstring> #include<algorithm> #define REP(i ...
- Mybatis解决了JDBC编程哪些问题
一:Mybatis简介 MyBatis是一个优秀的持久层框架,它对jdbc的操作数据库的过程进行封装,使开发者只需要关注 SQL 本身,而不需要花费精力去处理例如注册驱动.创建connection.创 ...