BZOJ3155: Preprefix sum
题解:
写过树状数组搞区间修改和区间求和的就可以秒出吧。。。
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 200000+5
#define maxm 20000000+5
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,m;
ll a[maxn],s[maxn][];
inline void add(int k,int x,ll y)
{
for(;x<=n;x+=x&(-x))s[x][k]+=y;
}
inline ll sum(int k,int x)
{
ll t=;
for(;x;x-=x&(-x))t+=s[x][k];
return t;
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();m=read();
for1(i,n){ll x=a[i]=read();add(,i,x);add(,i,i*x);}
char ch[];
while(m--)
{
scanf("%s",ch);
if(ch[]=='M')
{
ll x=read(),y=read();
add(,x,y-a[x]);add(,x,x*(y-a[x]));
a[x]=y;
}else
{
ll x=read();
printf("%lld\n",(x+)*sum(,x)-sum(,x));
}
}
return ;
}
题目:http://ch.ezoj.tk/contest/Katharon%20%EF%BC%831/Preprefix%20Sum
感觉bz上的题面怎么不一样。。。233
BZOJ3155: Preprefix sum的更多相关文章
- [bzoj3155]Preprefix sum(树状数组)
3155: Preprefix sum Time Limit: 1 Sec Memory Limit: 512 MBSubmit: 1183 Solved: 546[Submit][Status] ...
- BZOJ3155:Preprefix sum(线段树)
Description Input 第一行给出两个整数N,M.分别表示序列长度和操作个数 接下来一行有N个数,即给定的序列a1,a2,....an 接下来M行,每行对应一个操作,格式见题目描述 Out ...
- 树状数组【bzoj3155】: Preprefix sum
3155: Preprefix sum 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=3155 把给出的a_i当成查分数组d_i做就可以了 ...
- BZOJ 3155: Preprefix sum( 线段树 )
刷刷水题... 前缀和的前缀和...显然树状数组可以写...然而我不会, 只能写线段树了 把改变成加, 然后线段树维护前缀和, 某点p加, 会影响前缀和pre(x)(p≤x≤n), 对[p, n]这段 ...
- Preprefix sum BZOJ 3155 树状数组
题目描述 前缀和(prefix sum)Si=∑k=1iaiS_i=\sum_{k=1}^i a_iSi=∑k=1iai. 前前缀和(preprefix sum) 则把SiS_iSi作为原序列 ...
- 3155: Preprefix sum
3155: Preprefix sum https://www.lydsy.com/JudgeOnline/problem.php?id=3155 分析: 区间修改,区间查询,线段树就好了. 然后,这 ...
- 差分+树状数组【p4868】Preprefix sum
Description 前缀和(prefix sum)\(S_i=\sum_{k=1}^i a_i\). 前前缀和(preprefix sum) 则把\(S_i\)作为原序列再进行前缀和.记再次求得前 ...
- 2021.08.09 P4868 Preprefix sum(树状数组)
2021.08.09 P4868 Preprefix sum(树状数组) P4868 Preprefix sum - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 题意: 前缀和(pr ...
- BZOJ3155:Preprefix sum——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=3155 最朴素的想法是两棵树状数组,一个记录前缀和,一个记录前缀前缀和,但是第二个我们非常不好修改 ...
随机推荐
- Oracle 监听动态注册与静态注册
静态注册 静态注册是在启动listener时,listener会从listener.ora文件中获取服务名及相关信息.信息包括:实例名和服务名等. --静态注册时,listener.ora中的内容如下 ...
- Speech Patterns (string)
People often have a preference among synonyms of the same word. For example, some may prefer "t ...
- easy ui window 相关属性
<div class="easyui-window" title="提示" style="width:550px;height:500px;pa ...
- MySQL中字符串函数详细介绍
MySQL字符串函数对于针对字符串位置的操作,第一个位置被标记为1. ASCII(str)返回字符串str的 最左面字符的ASCII代码值.如果str是空字符串, 返回0.如果str是NULL,返回N ...
- The7th Zhejiang Provincial Collegiate Programming Contest->Problem A:A - Who is Older?
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3322 可以看样例猜题意的水题. #include<bits/stdc ...
- 对jQuery.extend()方法的分析
jQuery.extend方法是我们常用的方法,也是jQuery源码中的基础方法.它的主要作用是:将一个或多个“源对象”合并到一个“目标对象”中,并返回目标对象.它主要有三种表现形式: a.jQuer ...
- python语法-[with来自动释放对象]
python语法-[with来自动释放对象] http://www.cnblogs.com/itech/archive/2011/01/13/1934779.html 一 with python中的w ...
- c++ ANSI、UNICODE、UTF8互转
static std::wstring MBytesToWString(const char* lpcszString); static std::string WStringToMBy ...
- SDUT2191Calendar
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2191 题意:给你两个年月日,让你算出其中经历了 ...
- hdu 4675 GCD of Sequence
数学题! 从M到1计算,在计算i的时候,算出原序列是i的倍数的个数cnt: 也就是将cnt个数中的cnt-(n-k)个数变掉,n-cnt个数变为i的倍数. 且i的倍数为t=m/i; 则符合的数为:c[ ...