题目链接:https://www.luogu.org/problemnew/show/P3374

留个坑,以后补上BIT的讲解,先留下板子复习用

 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,m;
int tree[],a[];
int lowbit(int x)
{
return x&-x;
}
void add(int k,int num)//给k位置的数值加num
{
while(k<=n)
{
tree[k]+=num;
k+=lowbit(k);
}
}
int sum(int k)//前缀和
{
int s=;
while(k)
{
s+=tree[k];
k-=lowbit(k);
}
return s;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
add(i,a[i]);
}
for(int i=;i<=m;i++)
{
int c;scanf("%d",&c);
if(c == )
{
int x,k;
scanf("%d%d",&x,&k);
add(x,k);
}
else
{
int x,y;scanf("%d%d",&x,&y);
printf("%d\n",sum(y)-sum(x-));
}
}
return ;
}

【luogu P3374 树状数组1】 模板的更多相关文章

  1. 洛谷P3374树状数组1

    下有彩蛋(from https://www.cnblogs.com/wuwangchuxin0924/p/5921130.html)树状数组的blog写的最好的是这位//https://www.cnb ...

  2. 【luogu P3368 树状数组2】 模板

    题目链接:https://www.luogu.org/problemnew/show/P3368 #include<iostream> #include<cstdio> #in ...

  3. HDOJ-1156 Brownie Points II 线段树/树状数组(模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=1156 在一张二位坐标系中,给定n个点的坐标,玩一个划线游戏(线必须穿过点),Stan先手画一条垂直的线,然后Ol ...

  4. 洛谷 P3374 【模板】树状数组 1(单点加,区间和)

    题目链接 https://www.luogu.org/problemnew/show/P3374 树状数组 树状数组最基本的就是求区间和. 维护: 空间复杂度:O(n) 时间复杂度(区间和,单点修改) ...

  5. P3368 【模板】树状数组 2

    原题链接  https://www.luogu.org/problemnew/show/P3368 这个题和洛谷P3374树状数组1 有些不同,在普通的树状数组上运用了差分的知识.(由于P3374涉及 ...

  6. 敌兵布阵 HDU - 1166 (树状数组模板题,线段树模板题)

    思路:就是树状数组的模板题,利用的就是单点更新和区间求和是树状数组的强项时间复杂度为m*log(n) 没想到自己以前把这道题当线段树的单点更新刷了. 树状数组: #include<iostrea ...

  7. 树状数组(二叉索引树 BIT Fenwick树) *【一维基础模板】(查询区间和+修改更新)

    刘汝佳:<训练指南>Page(194) #include <stdio.h> #include <string.h> #include <stdlib.h&g ...

  8. 洛谷 P3368 【模板】树状数组 2 题解

    P3368 [模板]树状数组 2 题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某区间每一个数数加上x 2.求出某一个数的值 输入格式 第一行包含两个整数N.M,分别表示该数列数字的个 ...

  9. hdu 1394 Minimum Inversion Number (树状数组求逆序对)

    The inversion number of a given number sequence a1, a2, ..., an is the number of pairs (ai, aj) that ...

随机推荐

  1. 案例41-hibernate练习-添加客户

    1 utils部分 1 HibernateUtils package www.test.utils; import org.hibernate.Session; import org.hibernat ...

  2. vs2013下c++调用python脚本函数 出现的一些问题总结

    原文作者:aircraft 原文地址:https://www.cnblogs.com/DOMLX/p/9530834.html 首先是配置: 使用VS2013创建工程. 将libs中的python27 ...

  3. ife task0003学习笔记(二):JavaScript原型

    function aaa(){} aaa.prototype.bbb=function(){} var obj1=new aaa() var obj2=new aaa() obj1和obj2都有一个属 ...

  4. SecureCRT 连接 CentOS虚拟机

    SecureCRT 连接 CentOS虚拟机 1.安装SecureCRT SecureCRT是一款支持SSH等协议的终端仿真软件,可以在windows下登录Linux服务器,这样大大方便了开发工作.安 ...

  5. 一键压测工具改造(locust)

    本文内容来自“天外归云”大神,原文链接http://www.cnblogs.com/LanTianYou/p/5987741.html,目前只对启动脚本做了一些改造,应该说是,不适用powershel ...

  6. 九度oj题目1165:字符串匹配

    题目1165:字符串匹配 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3078 解决:1079 题目描述: 读入数据string[ ],然后读入一个短字符串.要求查找string[ ]中 ...

  7. windows下libcurl+openssl编译与使用配置

    之前使用过libcurl, 编译也是最简单的版本, 不需要openssl, 即不需要支持https, 所以编译和使用都很正常. 但要使用openssl就很麻烦了, 我花了差不多两天去编译和调用, 记录 ...

  8. [转]Show parameter & Table Not exists

    本文转自:http://www.cnblogs.com/fangwenyu/archive/2011/01/06/1926774.html 问题描述 在尝试通过show parameter来查看一个参 ...

  9. indexOf.substr,substring,charAt的区别

    var a = "asdfghjkl" alert(a.substr(1, 3));        //  从下标为1开始,往右数3个长度的数, 显示 sdf; alert(a.s ...

  10. C# url获取图片流转字符串

    //http url获取图片流转字符串 //string url = serverUrl.TrimEnd('/') + PUrl; //WebRequest request = WebRequest. ...