https://www.luogu.org/problemnew/show/P3374

单点修改,区间查询

#include <iostream>
#include <cstdio> using namespace std;
const int N = 5e5 + ; #define yxy getchar() int T[N], n, Ty; inline int read() {
int x = , f = ; char c = yxy;
while(c < '' || c > '') {if(c == '-') f = -; c = yxy;}
while(c >= '' && c <= '') x = x * + c - '', c = yxy;
return x * f;
} int lowbit(int x) {return x & (- x);} inline void Add(int id, int num) {
while(id <= n) {
T[id] += num;
id += lowbit(id);
}
} inline int Sum(int x) {
int ret = ;
while(x) {
ret += T[x];
x -= lowbit(x);
} return ret;
} int main() {
n = read();
Ty = read();
for(int i = ; i <= n; i ++) {
int x = read();
Add(i, x);
}
while(Ty --) {
int opt = read(), x = read(), y = read();
if(opt == ) Add(x, y);
else cout << Sum(y) - Sum(x - ) << endl;
} return ;
}

https://www.luogu.org/problemnew/show/P3368

区间修改,单点查询

#include <iostream>
#include <cstdio>
#include <algorithm> using namespace std;
const int N = 5e5 + ; #define yxy getchar() int T[N], A[N];
int n, Ty; inline int read() {
int x = , f = ;
char c = yxy;
while(c < '' || c > '') {
if(c == '-') f = -;
c = yxy;
}
while(c >= '' && c <= '') x = x * + c - '', c = yxy;
return x * f;
} inline int lowbit(int x) {
return x & - x;
} inline void Add(int x, int num) {
while(x <= n) {
T[x] += num;
x += lowbit(x);
}
} inline int Sum(int x) {
int ret = ;
while(x) {
ret += T[x];
x -= lowbit(x);
} return ret;
} int main() {
n = read();
Ty = read();
for(int i = ; i <= n; i ++) A[i] = read();
while(Ty --) {
int opt = read();
if(opt == ) {
int x = read(), y = read(), k = read();
Add(x, k); Add(y + , -k);
} else {
int x = read();
cout << A[x] + Sum(x) << endl;
}
}
return ;
}

P2068 统计和

https://www.luogu.org/problemnew/show/P2068

#include <iostream>
#include <cstdio> using namespace std;
const int N = 1e5 + ; #define yxy getchar()
#define R freopen("gg.in", "r", stdin) int T[N], n, Ty; inline int read() {
int x = , f = ; char c = yxy;
while(c < '' || c > '') {if(c == '-') f = -; c = yxy;}
while(c >= '' && c <= '') x = x * + c - '', c = yxy;
return x * f;
} inline int lowbit(int x) {
return x & (-x);
} inline void Add(int x, int y) {
while(x <= n) {
T[x] += y;
x += lowbit(x);
}
} inline int Sum(int x){
int ret = ;
while(x) {
ret += T[x];
x -= lowbit(x);
} return ret;
} int main() {
n = read();
Ty = read();
while(Ty --) {
char c = yxy;
int x = read(), y = read();
if(c == 'x') Add(x, y);
else cout << Sum(y) - Sum(x - ) << endl;
}
return ;
}

最新文章

  1. 为MySQL选择合适的备份方式
  2. C#读写txt文件的两种方法介绍
  3. C++安装失败解决办法
  4. linux下的调试工具ltrace与strace
  5. PHP 内存的分布问题
  6. Java Calendar实现控制台日历
  7. WindowsServer2012 取消密码策略
  8. showModalDialog-父窗体子窗体
  9. Selenium 上传文件失败,解决办法一
  10. 网络通信 --&gt; 互联网协议(一)
  11. Tomcat常用的过滤器
  12. SparkCore | Rdd| 广播变量和累加器
  13. Unity配置安卓开发环境
  14. 【SoftwareTesting】Homework3
  15. Android开发 android沉浸式状态栏的适配(包含刘海屏)转载
  16. Python 事件驱动了解
  17. .net mvc数据库操作添加数据的几中方法
  18. mysql命令行导入结构化数据
  19. android设备不识别awk命令,缺少busybox
  20. jsp之radio取值与赋值

热门文章

  1. Neo4j基本使用及导入三元组
  2. 图像识别领域的一些code
  3. centos mysql数据库问题:ERROR 1044 (42000): Access denied for user &#39;&#39;@&#39;localhost&#39; to database &#39;mysql&#39;(转)
  4. /sockjs-node/info 报错问题
  5. # 机器学习算法总结-第九天(XGboost)
  6. 苹果发布app,上传ipa,不显示问题
  7. C#的预处理指令
  8. Data truncation: Incorrect datetime value: &#39;May 15, 2019 4:15:37 PM
  9. Tcp/IP协议详讲
  10. 基于栈的指令集与基于寄存器的指令集详细比对及JVM执行栈指令集实例剖析