「BZOJ3155」Preprefix sum

2014年5月29日4,1852

Description

Input

第一行有两个整数N和M,分别表示序列长度和操作个数。

接下来的一行有N个整数,即给定的序列a1,a2….an。

接下来有M行,每行对应一个操作,格式见题目描述。

Output

对于每个询问操作,输出一行,表示所询问的SSi的值。

Sample Input

5 3
1 2 3 4 5
Query 5
Modify 3 2
Query 5

Sample Output

35
32

HINT

1<=N,M<=100000,且在任意时刻0<=Ai<=100000

题解

开俩个树状数组,第一个维护a[i]前缀和

第二个维护(n-i+1)*a[i]的前缀和

t2[x]-t1[x]*(n-x)

avatar
1 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
hzwerMinicheshire Recent comment authors
  Subscribe  
提醒
Minicheshire
Minicheshire

学长,您的图片贴错了>_<