
树状数组
文章平均质量分 93
csu_xiji
这个作者很懒,什么都没留下…
展开
-
树状数组(Markdown版本)
什么是树状数组:树状数组(Binary Indexed Tree(B.I.T), Fenwick Tree)是一个查询和修改复杂度都为log(n)log(n)log(n)的数据结构。它能用来干什么:最经典的应用就是查询某一段区间元素的和,而且支持在线修改操作。如果没有修改操作,就没必要用树状数组了。它和线段树有什么关系:实际上树状数组就是没有右儿子的线段树,它实现起来比线段树简单,而且效率更高,空间占用的也更少。但是能用树状数组解决的问题,基本上都能用线段树解决。(反过来就不是了)我还是不原创 2021-08-01 01:13:35 · 373 阅读 · 0 评论 -
洛谷 P2161 [SHOI2009]会场预约 树状数组+二分
https://www.luogu.org/problem/P2161题目描述PP大厦有一间空的礼堂,可以为企业或者单位提供会议场地。这些会议中的大多数都需要连续几天的时间(个别的可能只需要一天),不过场地只有一个,所以不同的会议的时间申请不能够冲突。也就是说,前一个会议的结束日期必须在后一个会议的开始日期之前。所以,如果要接受一个新的场地预约申请,就必须拒绝掉与这个申请相冲突的预约。 一般来...原创 2019-10-26 13:45:21 · 232 阅读 · 0 评论 -
洛谷 P1972 [SDOI2009]HH的项链 离线+树状数组
https://www.luogu.org/problem/P1972题目背景无题目描述HH 有一串由各种漂亮的贝壳组成的项链。HH 相信不同的贝壳会带来好运,所以每次散步完后,他都会随意取出一段贝壳,思考它们所表达的含义。HH 不断地收集新的贝壳,因此,他的项链变得越来越长。有一天,他突然提出了一个问题:某一段贝壳中,包含了多少种不同的贝壳?这个问题很难回答……因为项链实在是太长了。于是...原创 2019-10-25 22:03:18 · 138 阅读 · 0 评论 -
洛谷 P3368 树状数组 差分树状数组
https://www.luogu.org/problem/P3368题目描述如题,已知一个数列,你需要进行下面两种操作:1.将某区间每一个数数加上x2.求出某一个数的值输入格式第一行包含两个整数N、M,分别表示该数列数字的个数和操作的总个数。第二行包含N个用空格分隔的整数,其中第i个数字表示数列第i项的初始值。接下来M行每行包含2或4个整数,表示一个操作,具体如下:操作1: 格...原创 2019-10-18 16:02:16 · 130 阅读 · 0 评论 -
区间动态第k大模板(树状数组套主席树)
原理:https://blog.youkuaiyun.com/g21wcr/article/details/86652152https://blog.youkuaiyun.com/u014664226/article/details/47839973板子一:时空复杂度:O((n+q)*logn*logn)洛谷 P2617#include<bits/stdc++.h>using...原创 2019-07-26 14:12:38 · 277 阅读 · 0 评论 -
ZOJ 2112 动态区间第k大 树状数组套主席树
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2112The Company Dynamic Rankings has developed a new kind of computer that is no longer satisfied with the query like to simply find the ...原创 2019-07-26 14:17:49 · 257 阅读 · 0 评论 -
acwing 246 区间最大公约数 线段树+树状数组+差分
https://www.acwing.com/problem/content/247/?time=1564925894116给定一个长度为N的数列A,以及M条指令,每条指令可能是以下两种之一:1、“C l r d”,表示把 A[l],A[l+1],…,A[r] 都加上 d。2、“Q l r”,表示询问 A[l],A[l+1],…,A[r] 的最大公约数(GCD)。对于每个询问,输出一个整数...原创 2019-08-05 00:01:51 · 435 阅读 · 0 评论 -
CodeChef DGCD Dynamic GCD 树链剖分+线段树维护gcd
https://www.codechef.com/problems/DGCDYou’re given a tree on N vertices. Each vertex has a positive integer written on it, number on the ith vertex being vi. Your program must process two types of qu...原创 2019-08-05 15:20:34 · 247 阅读 · 0 评论 -
POJ 2763 Housewife Wind LCA+树状数组 dfs序
http://poj.org/problem?id=2763After their royal wedding, Jiajia and Wind hid away in XX Village, to enjoy their ordinary happy life. People in XX Village lived in beautiful huts. There are some pair...原创 2019-08-01 19:30:53 · 154 阅读 · 0 评论 -
HDU 6203 ping ping ping LCA+dfs序+树状数组
http://acm.hdu.edu.cn/showproblem.php?pid=6203The structure of the computer room in Northeastern University is pretty miraculous. There are n servers, some servers connect to the gateway whose IP add...原创 2019-08-09 15:56:34 · 165 阅读 · 0 评论 -
POJ 1990 MooFest 树状数组
http://poj.org/problem?id=1990Every year, Farmer John's N (1 <= N <= 20,000) cows attend "MooFest",a social gathering of cows from around the world. MooFest involves a variety of events includi...原创 2019-08-09 18:27:01 · 171 阅读 · 0 评论 -
HDU 3015 Disharmony Trees 树状数组
http://acm.hdu.edu.cn/showproblem.php?pid=3015One day Sophia finds a very big square. There are n trees in the square. They are all so tall. Sophia is very interesting in them.She finds that trees m...原创 2019-08-10 11:09:01 · 161 阅读 · 0 评论 -
洛谷 P2617 Dynamic Rankings 树状数组套主席树(动态区间第k大)
https://www.luogu.org/problem/P2617题目描述给定一个含有n个数的序列a[1],a[2],a[3]……a[n],程序必须回答这样的询问:对于给定的i,j,k,在a[i],a[i+1],a[i+2]……a[j]中第k小的数是多少(1≤k≤j-i+1),并且,你可以改变一些a[i]的值,改变后,程序还能针对改变后的a继续回答上面的问题。你需要编一个这样的程序,从...原创 2019-07-26 11:23:45 · 180 阅读 · 0 评论 -
CodeForces 1187 D 树状数组
链接:http://codeforces.com/problemset/problem/1187/DYou are given an array a1,a2,…,an and an array b1,b2,…,bn.For one operation you can sort in non-decreasing order any subarray a[l…r]of the arr...原创 2019-07-22 10:48:57 · 313 阅读 · 0 评论 -
CSU 2186 Medicine加强版 二维树状数组
http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2186Description给出一个n*m的矩阵(下标从1开始),即n个长度为m的字符串(仅由小写字母组成)一共有q个操作需要处理操作0:0 x y z将下标为(x,y)处的字母改为z字母操作1:1 x1 y1 x2 y2 询问矩形(x1<=x<=x2...原创 2019-05-15 15:06:11 · 143 阅读 · 0 评论 -
HDU 1166 树状数组
http://acm.hdu.edu.cn/showproblem.php?pid=1166C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动...原创 2019-03-09 15:34:25 · 165 阅读 · 0 评论 -
HDU 1754 树状数组做法
http://acm.hdu.edu.cn/showproblem.php?pid=1754很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。这让很多学生很反感。不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。Input本题目包含多组测试,请处理到文件结束。在每个测试的第一行...原创 2019-03-09 15:42:08 · 566 阅读 · 1 评论 -
CSU 1770 按钮控制彩灯实验
http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=1770应教学安排,yy又去开心的做电学实验了。实验的内容分外的简单一串按钮通过编程了的EEPROM可以控制一串彩灯。然而选择了最low的一种一对一的控制模式,并很快按照实验指导书做完实验的yy马上感觉到十分无趣。于是他手指在一排按钮上无聊的滑来滑去,对应的彩灯也不断的变化着开关。...原创 2019-03-09 15:47:20 · 266 阅读 · 0 评论 -
hihocoder 1336 二维树状数组
http://hihocoder.com/problemset/problem/1336You are given an N × N matrix. At the beginning every element is 0. Write a program supporting 2 operations:1. Add x y value: Add value to the element ...原创 2019-03-09 16:00:03 · 151 阅读 · 0 评论 -
POJ 2299 求逆序数 归并排序||离散化&权值树状数组
http://poj.org/problem?id=2299In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence element...原创 2019-03-09 16:10:51 · 188 阅读 · 0 评论 -
HDU 6318 逆序数
http://acm.hdu.edu.cn/showproblem.php?pid=6318Long long ago, there was an integer sequence a.Tonyfang think this sequence is messy, so he will count the number of inversions in this sequence. Becau...原创 2019-03-09 16:19:27 · 326 阅读 · 0 评论 -
HDU 1541 树状数组
http://acm.hdu.edu.cn/showproblem.php?pid=1541Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be...原创 2019-03-09 17:15:25 · 132 阅读 · 0 评论 -
HDU 5775 树状数组求逆序数
http://acm.hdu.edu.cn/showproblem.php?pid=5775Long long ago, there was an integer sequence a.Tonyfang think this sequence is messy, so he will count the number of inversions in this sequence. Becau...原创 2019-03-11 00:27:37 · 136 阅读 · 0 评论 -
权值树状数组的简单介绍
什么是权值数组:for i =1 to n do ++A[a[i]]也就是说,权值数组的A[i]存储的是给定序列a[1]-a[n]中等于i的元素个数。权值数组的前缀和:for i = minval+1 to maxval do A[i]+=A[i-1]minval=min{a[i]} maxval=max{a[i]}也就是说,权值数组的前缀和A[i]就表示原序列a[...原创 2019-03-13 18:50:48 · 2987 阅读 · 4 评论 -
HDU 2852 树状数组+二分查询
http://acm.hdu.edu.cn/showproblem.php?pid=2852For the k-th number, we all should be very familiar with it. Of course,to kiki it is also simple. Now Kiki meets a very similar problem, kiki wants to d...原创 2019-03-13 19:01:46 · 279 阅读 · 0 评论 -
CSU 2222 权值树状数组
http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2222DescriptionWells有一个长度为N的数列Ai,这N个数互不相同Wells已经计算完成了每个数对逆序对数量的贡献,也就是位置处于这个数之前但比这个数大的数的个数现在Wells想请你通过这些信息复原原数列Input第一行包含一个正整数N(N<...原创 2019-05-02 22:02:03 · 477 阅读 · 0 评论 -
树状数组详解
什么是树状数组:树状数组(Binary Indexed Tree(B.I.T), Fenwick Tree)是一个查询和修改复杂度都为log(n)的数据结构。它能用来干什么:最经典的应用就是查询某一段区间元素的和,而且支持在线修改操作。如果没有修改操作,就没必要用树状数组了。它和线段树有什么关系:实际上树状数组就是没有右儿子的线段树,它实现起来比线段树简单,而且效率更高,空...原创 2019-03-09 15:31:22 · 351 阅读 · 0 评论