![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
树状数组
ssl_yty
这个作者很懒,什么都没留下…
展开
-
【51nod】【树状数组】 小陶与杠铃片
【51nod】【树状数组】 小陶与杠铃片题目解题思路要将后面轻的往前放,其实就是求逆序对得出前面有多少比当前小的,剩下的与当前构成逆序对代码#include<iostream>#include<cstdio>using namespace std;const int N=200001;int n,x;long long tree[210000],ans;void add(int x){ for (;x<=N;x+=x&(-x))原创 2022-01-12 20:45:33 · 134 阅读 · 0 评论 -
【51nod】【树状数组】小陶的疑惑2
【51nod】【树状数组】小陶的疑惑2题目解题思路差分是通过前缀和来表示当前的数树状数组可以查询前缀和问题解决(^ o ^)/代码#include<iostream>#include<cstdio>using namespace std;long long n,m,w,x,l,r,b[200010],a[200010];long long tree[200010];void add(int y){ for (;y<=n;y+=y&(原创 2022-01-12 20:21:27 · 88 阅读 · 0 评论 -
【51nod】【树状数组】 堆积木
【51nod】【树状数组】 堆积木题目解题思路先理解题意,因为可以旋转,所以对于一个积木有三种底面其实题目和小明爱拦截很像肯定要确定一个坐标的顺序,再求另一个坐标的比它小的先将y从小到大排序,然后给tm一个编号(相同的用一个)接着再按x从小到大排序,这时x就是有序的(要注意相同时的处理)以编号为下标,树状数组维护高度统计比当前的编号小的最大高度,加上其高度即为以当前为底的最高高度代码#include<algorithm>#include<iostream&g原创 2022-01-12 20:08:48 · 142 阅读 · 0 评论 -
【树状数组】 小明爱拦截
【树状数组】 小明爱拦截题目解题思路求最长不上升序列将导弹高度从大到小排序以tm的发射时间为下标,将以其结尾的拦截最大值丢进树状数组维护在当前导弹发射时间前并进了树状数组的(也就是高度比当前的大),可以拦截当前导弹那么求其拦截最大值+1,即为当前导弹是最后一个可以拦截的最多代码#include<algorithm>#include<iostream>#include<cstdio>using namespace std;struct lzf原创 2022-01-12 19:40:51 · 82 阅读 · 0 评论 -
【gmoj】【树状数组】【st表】No Time to Dry
【gmoj】【树状数组】【st表】No Time to Dry题目洛谷 P7416解题思路qwq,第一题放紫题,人麻了看到区间想到树状数组 or 线段树手推一下会发现区间[l…r]且s[l]==s[r]时,如果中间有数小于s[l],那么s[r]必须要靠操作一次来涂色那么先预处理出一个bf数组维护当前颜色上一次出现的位置如果当前和上一次之间没有比它们小的,说明涂色可以传递,那就在上一次出现的位置+1加一次操作如果上一次位置不在区间内,是要加1的,如果在区间内不影响结果否则要单独涂一次,原创 2021-08-16 20:43:53 · 76 阅读 · 0 评论 -
【gmoj】【树状数组】 United Cows of Farmer John
【gmoj】【树状数组】 United Cows of Farmer John题目解题思路因为领队不能和另一个领队以及队员一样用树状数组维护不同数字的种数加1说明多了一种新的数字假设当前数在之前出现过求i-1~v[a[i]]+1这一段内的不同数字种数即为答案然后消除v[a[i]]这个数字对后面产生的贡献 因为当前数更右加上当前数i的贡献代码#include<iostream>#include<cstdio>using namespace std;in原创 2021-08-14 15:10:56 · 105 阅读 · 0 评论 -
【gmoj】【NOIP2013模拟联考11】 【树状数组】 【离散化】矩形
【gmoj】【NOIP2013模拟联考11】 【树状数组】 【离散化】矩形题目解题思路先将点的坐标离散化然后按高低排序先枚举较低的一条横边 选出满足条件的竖边再枚举高的横边 剔除掉不符合条件的满足条件的竖边个数用树状数组维护最后得到满足条件的竖边个数为tot那么ta对答案的贡献为 tot(tot-1)/2代码#include<algorithm>#include<iostream>#include<cstring>#include&原创 2021-07-20 21:13:44 · 72 阅读 · 0 评论 -
【ybtoj 高效进阶 4.2】 【树状数组】 区间修改区间查询
【ybtoj 高效进阶 4.2】 【树状数组】 区间修改区间查询题目解题思路区间修改可以用查分例如区间l—r,在l处加,在r+1处减,这一段的前缀和将会改变一个数组维护加的数,一个数组维护前缀代码#include<iostream>#include<cstdio>using namespace std;long long z,n,m,l,r,w,a[1000010],c[1000010],f[1000010];void put(long long x,l原创 2021-07-09 16:35:19 · 104 阅读 · 0 评论 -
【ybtoj 高效进阶 4.2】【树状数组】 严格上升子序列
【ybtoj 高效进阶 4.2】【树状数组】 严格上升子序列题目解题思路由题得,可用DP解f[i][j]表示以第i个数为结尾长度为j的上升子序列当长度为1时,方案数为1f[i][j]=1;当长度>1时,方案数为以小于a[i]的所有数结尾长为j-1的和f[i][j]+=f[k][j-1];时间复杂度挺让人绝望的????将数组离散化建m个树状数组(二维表示),维护长度1~m的放案数用来优化DP代码#include<algorithm>#include<原创 2021-07-09 16:10:04 · 161 阅读 · 0 评论 -
【ybtoj 高效进阶 4.2】 【树状数组】 逆序对
【ybtoj 高效进阶 4.2】 【树状数组】 逆序对题目解题思路先将a_i离散化将a_i按值排序,去重再按原来位置排序加入按值排序时的位置然后用自己原来位置减去在自己加入之前且小于自己的个数代码#include<algorithm>#include<iostream>#include<cstdio>using namespace std;struct lzf{ int z,x,i;}a[500010];int n,k=1; lon原创 2021-06-12 18:08:53 · 109 阅读 · 0 评论 -
【ybtoj 高效进阶 4.2】【树状数组】 单点修改区间查询
【ybtoj 高效进阶 4.2】【树状数组】 单点修改区间查询题目解题思路模板题详细解释,戳戳这里代码#include<iostream>#include<cstdio>using namespace std;int n,m,x,y,w;long long c[1000010]; void add(int x,int y) //修改{ for (;x<=n;x+=x&(-x)) c[x]+=y;}long long原创 2021-06-12 17:02:59 · 76 阅读 · 0 评论 -
洛谷 CF261D Maxim and Increasing Subsequence 题解
洛谷 CF261D Maxim and Increasing Subsequence 题解洛谷 CF261D题目Maxim loves sequences, especially those that strictly increase. He is wondering, what is the length of the longest increasing subsequence of the given sequence aaa?Sequence aaa is given as follo原创 2020-08-19 10:28:22 · 116 阅读 · 0 评论 -
POJ 3378 Crazy Thairs 题解
POJ 3378 Crazy Thairs 题解POJ 3378题目These days, Sempr is crazed on one problem named Crazy Thair. Given N (1 ≤ N ≤ 50000) numbers, which are no more than 109, Crazy Thair is a group of 5 numbers {i, j, k, l, m} satisfying:1 ≤ i < j < k < l &l原创 2020-08-19 09:45:53 · 202 阅读 · 0 评论 -
POJ 3321 Apple Tree 题解
POJ 3321 Apple Tree 题解POJ 3321题目There is an apple tree outside of kaka’s house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very much, so he has been carefully nurturing the big apple tree.The tree has N forks which are conne原创 2020-08-19 09:18:00 · 317 阅读 · 0 评论 -
URAL 1028 数星星 题解
数星星 题解URAL 1028题目Astronomers 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 an amount of the stars that are not higher and not to the right of the given star原创 2020-08-18 11:29:10 · 455 阅读 · 0 评论 -
校门外的树 (树状数组)题解
校门外的树 (树状数组)题解校门外的树题目校门外有很多树,有苹果树,香蕉树,有会扔石头的,有可以吃掉补充体力的……如今学校决定在某个时刻在某一段种上一种树,保证任一时刻不会出现两段相同种类的树,现有两个操作:KKK=1,读入lll,rrr表示在lll~rrr之间种上的一种树KKK=2,读入lll,rrr表示询问l~r之间能见到多少种树(lll,rrr>0)输入第一行nnn,mmm表示道路总长为nnn,共有mmm个操作接下来mmm行为mmm个操作输出对于每个kkk=2输出一原创 2020-08-18 07:25:08 · 810 阅读 · 0 评论