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

题目链接:https://www.luogu.org/problemnew/show/P3374 留个坑,以后补上BIT的讲解,先留下板子复习用 #include<iostream> #include<cstdio> #include<cstring> using namespace std; int n,m; ],a[]; int lowbit(int x) { return x&-x; } void add(int k,int num)//给k位置的数值加n…
下有彩蛋(from https://www.cnblogs.com/wuwangchuxin0924/p/5921130.html)树状数组的blog写的最好的是这位//https://www.cnblogs.com/wuwangchuxin0924/p/5921130.html//(声明一下跟我没有半毛钱关系,我是一个热爱珂学的好孩子)我要说的主要是怎么去学习树状数组,刚开始我也无从下手,但是我想到了一个方法,虽然我不知道怎么实现,但我知道代码的意思和实现的原理,所以我对照他(她)的代码在看着…
题目链接:https://www.luogu.org/problemnew/show/P3368 #include<iostream> #include<cstdio> #include<cstring> using namespace std; int n,m; ],a[]; int lowbit(int x) { return x&-x; } void add(int k,int num)//给k位置的数值加num { while(k<=n) { tr…
http://acm.hdu.edu.cn/showproblem.php?pid=1156 在一张二位坐标系中,给定n个点的坐标,玩一个划线游戏(线必须穿过点),Stan先手画一条垂直的线,然后Ollie画一条水平的线(要求要穿过Stan那条线所穿过的某个点).划分后,左上和右下点数是Ollie 的得分,左下和右上是Stan的得分.求Stan在保证最低得分(即不论Ollie后手怎么划,Stan最少能的的分数)最高,并给出基于符合的先手划法,Ollie后手的各种划线的得分(需要去重),升序输出.…
题目链接 https://www.luogu.org/problemnew/show/P3374 树状数组 树状数组最基本的就是求区间和. 维护: 空间复杂度:O(n) 时间复杂度(区间和,单点修改): 修改:O(logn) 查询:O(logn) 用c[i]表示(i-lowbit[i]+1,i)区间的和. 查询时,用到前缀和的思想,(i,j)=c[j]-c[i-1]. 优点 代码简单 缺点 难理解 代码(解析) #include<iostream> #include<cstdio>…
原题链接  https://www.luogu.org/problemnew/show/P3368 这个题和洛谷P3374树状数组1 有些不同,在普通的树状数组上运用了差分的知识.(由于P3374涉及到一些较为基础的知识,就先不讲了,反正大家都会了QwQ~): 什么是差分呢? 差分差分,顾名思义就是相差的分数啦 ,其实就是每一项与前一项的差距,通常我们用d数组来表示. 举个例子,假如我们有一个序列: a1=1,a2=5,a3=6,a4=3,a5=4: 那么可以计算出每一项的差分: d1=a1 -…
思路:就是树状数组的模板题,利用的就是单点更新和区间求和是树状数组的强项时间复杂度为m*log(n) 没想到自己以前把这道题当线段树的单点更新刷了. 树状数组: #include<iostream> #include<cstdio> #include<cstring> using namespace std; ; int tree[maxn], n; void add(int k, int num) { while (k <= n) { tree[k] += nu…
刘汝佳:<训练指南>Page(194) #include <stdio.h> #include <string.h> #include <stdlib.h> #include <algorithm> using namespace std; //一维树状数组基础模板 int lowbit(int x) { return x&(-x); } int c[1001]; int sum(int x) //计算从1到x的数组元素的和 { int…
P3368 [模板]树状数组 2 题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某区间每一个数数加上x 2.求出某一个数的值 输入格式 第一行包含两个整数N.M,分别表示该数列数字的个数和操作的总个数. 第二行包含N个用空格分隔的整数,其中第i个数字表示数列第i项的初始值. 接下来M行每行包含2或4个整数,表示一个操作,具体如下: 操作1: 格式:1 x y k 含义:将区间[x,y]内每个数加上k 操作2: 格式:2 x 含义:输出第x个数的值 输出格式 输出包含若干行整数,即…
The inversion number of a given number sequence a1, a2, ..., an is the number of pairs (ai, aj) that satisfy i < j and ai > aj. For a given sequence of numbers a1, a2, ..., an, if we move the first m >= 0 numbers to the end of the seqence, we wil…