可以把每个公式都化简,然后得到要维护的东西就是平方和,和前缀和,两个bit即可

不能cin,超时。IOS后都不行。

scanf用lld

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
#define MY "H:/CodeBlocks/project/CompareTwoFile/DataMy.txt", "w", stdout
#define ANS "H:/CodeBlocks/project/CompareTwoFile/DataAns.txt", "w", stdout #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = 1e6 + ;
int n, m;
LL c_pow[maxn];
LL c[maxn];
LL a[maxn];
int lowbit(int x) {
return x & (-x);
}
void upDate_pow(int pos, LL val) {
while (pos <= n) {
c_pow[pos] += val;
pos += lowbit(pos);
}
}
void upDate(int pos, LL val) {
while (pos <= n) {
c[pos] += val;
pos += lowbit(pos);
}
}
LL query_pow(int pos) {
LL ans = ;
while (pos > ) {
ans += c_pow[pos];
pos -= lowbit(pos);
}
return ans;
}
LL query(int pos) {
LL ans = ;
// if (pos < 0) arrest
while (pos > ) {
ans += c[pos];
pos -= lowbit(pos);
}
return ans;
}
void work() {
scanf("%d%d", &n, &m);
for (int i = ; i <= n; ++i) {
scanf("%lld", &a[i]);
upDate(i, a[i]);
upDate_pow(i, a[i] * a[i]);
}
bool flag1 = false;
for (int i = ; i <= m; ++i) {
int flag;
scanf("%d", &flag);
if (flag == ) {
int x, y;
scanf("%d%d", &x, &y);
LL now = query(x) - query(x - );
upDate(x, -now);
upDate(x, y); now = query_pow(x) - query_pow(x - );
upDate_pow(x, -now);
upDate_pow(x, y * y);
} else {
int L, R;
scanf("%d%d", &L, &R);
LL t1 = (query_pow(R) - query_pow(L - )) * (R - L + );
LL haha = query(R) - query(L - );
LL t2 = - * haha * haha;
LL t3 = t2 / -;
printf("%lld\n", t1 + t2 + t3);
}
}
}
int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
work();
return ;
}

“玲珑杯”ACM比赛 Round #5 H -- Variance 简单树状数组的更多相关文章

  1. 【“玲珑杯”ACM比赛 Round #20 H】康娜的数学课

    [链接]http://www.ifrog.cc/acm/problem/1161 [题意] 在这里写题意 [题解] 首先x<l肯定无解; 然后,肯定是要选其中的一些数字的. 而且这些数字肯定是大 ...

  2. “玲珑杯”ACM比赛 Round #12题解&源码

    我能说我比较傻么!就只能做一道签到题,没办法,我就先写下A题的题解&源码吧,日后补上剩余题的题解&源码吧!                                     A ...

  3. “玲珑杯”ACM比赛 Round #19题解&源码【A,规律,B,二分,C,牛顿迭代法,D,平衡树,E,概率dp】

    A -- simple math problem Time Limit:2s Memory Limit:128MByte Submissions:1599Solved:270 SAMPLE INPUT ...

  4. “玲珑杯”ACM比赛 Round #19 B -- Buildings (RMQ + 二分)

    “玲珑杯”ACM比赛 Round #19 Start Time:2017-07-29 14:00:00 End Time:2017-07-29 16:30:00 Refresh Time:2017-0 ...

  5. “玲珑杯”ACM比赛 Round #1

    Start Time:2016-08-20 13:00:00 End Time:2016-08-20 18:00:00 Refresh Time:2017-11-12 19:51:52 Public ...

  6. “玲珑杯”ACM比赛 Round #18

    “玲珑杯”ACM比赛 Round #18 Start Time:2017-07-15 12:00:00 End Time:2017-07-15 15:46:00 A -- 计算几何你瞎暴力 Time ...

  7. Codeforces Round #261 (Div. 2) D 树状数组应用

    看着题意:[1,i]中等于a[i]的个数要大于[,jn]中等于a[j]的个数 且i<j,求有多少对这种(i,j)  ,i<j可是 i前面的合法个数 要大于j后面的 看起来非常像逆序数的样子 ...

  8. Codeforces Round #365 (Div. 2) D 树状数组+离线处理

    D. Mishka and Interesting sum time limit per test 3.5 seconds memory limit per test 256 megabytes in ...

  9. Codeforces Gym 100114 H. Milestones 离线树状数组

    H. Milestones Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descripti ...

随机推荐

  1. Java中的文件上传和下载

    文件上传原理: 早期的文件上传机制: 在TCP/IP中.最早出现的文件上传机制是FTP.他是将文件由客户端发送到服务器的标准机制. jsp中的文件上传机制: 在jsp编程中不能使用FTP的方法来上传文 ...

  2. 登录日志的访问日志的 统计 MapReduce

    登录日志的访问日志的 统计    MapReduce <!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-commo ...

  3. Exchangeable image file format

    Exif - Wikipedia https://en.wikipedia.org/wiki/Exif

  4. Lesson one of python

    Test1:Use the powershell to output the contents print "Hello World!" print "Hello Aga ...

  5. lucene 5的测试程序——API变动太大

    package hello; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import ...

  6. Oracle10G各版本下载以及补丁地址

    Oracle Database 10g Release 2 (10.2.0.1.0) Enterprise/Standard Edition for Microsoft Windows (32-bit ...

  7. SPOJ:String Play (?)

    String Play Milo has a string S of length L. Tutu picks a random prefix and Mota picks a random suff ...

  8. [Selenium] Actions.doubleClick

    WebElement el = page.getTable_AssetMixesName().get(index); Actions action = new Actions(driver); act ...

  9. Map集合的几种遍历方式

    Map<String ,String> map=new HashMap<String,String>(); map.put("1","value1 ...

  10. .NETFramework:Cache

    ylbtech-.NETFramework:Cache 1.返回顶部 1. #region 程序集 System.Web, Version=4.0.0.0, Culture=neutral, Publ ...