随笔分类 -  数据结构--线段树,树状数组

摘要:题:https://www.luogu.org/problem/P2221#submit 求:ans=i=l∑r​a[i]∗(r−i+1)(i−l+1) #include<bits/stdc++.h> using namespace std; typedef long long ll; #defin 阅读全文
posted @ 2019-09-12 12:48 starve_to_death 阅读(159) 评论(0) 推荐(0)
摘要:题:https://nanti.jisuanke.com/t/41350 分析:先将字符串转置过来 状态转移,因为只有5个状态,所以 i 状态到 j 状态的最小代价就枚举【i】【k】->【k】【j】的最小值(0<=k<=4) 0:初始状态 1:2 2:20 3:201 4:2019 mat[i][j 阅读全文
posted @ 2019-09-09 22:41 starve_to_death 阅读(172) 评论(0) 推荐(0)
摘要:简单的树链剖分+线段树 #include<bits\stdc++.h> using namespace std; #define pb push_back #define lson root<<1,l,midd #define rson root<<1|1,midd+1,r const int M= 阅读全文
posted @ 2019-08-30 09:11 starve_to_death 阅读(151) 评论(0) 推荐(0)
摘要:https://ac.nowcoder.com/acm/contest/890/F 题意:二维平面中有n个气球,你可以横着社三法子弹,竖着射三发子弹,且横着子弹的关系是y,y+r,y+2*r,竖着是x,x+r,x+2*r。问你怎么射才能射爆最多的气球。 分析:(代码注释) #include<bits 阅读全文
posted @ 2019-08-19 14:42 starve_to_death 阅读(202) 评论(0) 推荐(0)
摘要:https://ac.nowcoder.com/acm/contest/887/E 树状数组做法(代码有注释) #include<bits/stdc++.h> using namespace std; typedef long long ll; const int M=4e5+5; int x[M] 阅读全文
posted @ 2019-08-19 11:46 starve_to_death 阅读(146) 评论(0) 推荐(0)
摘要:题意:有n种树,给出每种数的高度、移除的花费和数量,求最小花费是多少使得剩下树中最高的树的数量占一半以上。 分析:以高度排序,枚举每一高度,对当前枚举到的这个高度视为最高高度,数目由num棵,然后后面肯定要砍掉因为比他高,然后再考虑比他小的,因为要构成俩倍的关系,所以最多保留num-1棵。 #inc 阅读全文
posted @ 2019-08-10 05:33 starve_to_death 阅读(743) 评论(0) 推荐(0)
摘要:https://www.cnblogs.com/mountaink/p/9878918.html 分析:每次的选取必须选最优的一条链,那我们考虑一下选择这条链后,把这条路上的点的权值更新掉,再采取选最优的一条链的策略,如此往复。 所以考虑利用dfs序来处理线段树,线段树维护的是最最优链的值,已经这条 阅读全文
posted @ 2019-07-19 16:07 starve_to_death 阅读(180) 评论(0) 推荐(0)
摘要:学习:https://www.cnblogs.com/lcf-2000/p/5866170.html 题目:http://codevs.cn/problem/1082/ #include<iostream> #include<cstring> #include<cstdio> #include<al 阅读全文
posted @ 2019-07-14 21:54 starve_to_death 阅读(123) 评论(0) 推荐(0)
摘要:hdu2642 http://acm.hdu.edu.cn/showproblem.php?pid=2642 题目大意: 现在假设天空是一个二维平面(1000*1000)。坐标从(0,0)点开始。现在给出N条信息。 "B X Y",B为字符,x、y是整数,表示将坐标(x,y)的星星变亮。 "D XY 阅读全文
posted @ 2019-07-14 10:00 starve_to_death 阅读(272) 评论(0) 推荐(0)
摘要:题意:给定一个正整数n,和一个1-n的一个排列,每个数可以和旁边的两个数的任意一个交换,每交换一次总次数就要加一,问将这个排列转换成一个递增的排列需要多少次交换? 题意可以转换成求这个排列的逆序对数。 #include<iostream> #include<cstdio> #include<cstr 阅读全文
posted @ 2019-07-13 22:00 starve_to_death 阅读(122) 评论(0) 推荐(0)
摘要:https://codeforces.com/contest/1187/problem/D 题意:选取a序列的一段【l,r】将选中的区间按非降排序。问能否经过若干次操作后形成b序列; 分析:b序列的数的总类及各个类的数目一定要与a序列相同; 对b的每个位置的值,找到与之相同的a序列中还没有被用的位置 阅读全文
posted @ 2019-07-09 15:45 starve_to_death 阅读(142) 评论(0) 推荐(0)
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 const int M=3e5+5; 4 struct node{ 5 int l,r,cnt,lazy; 6 node(int l1=0,int r1=0,int cnt1=0,int lazy1 阅读全文
posted @ 2019-05-09 18:15 starve_to_death 阅读(123) 评论(0) 推荐(0)
摘要:在写的时候加了判断询问位置先后的swap结果wa了快十次了,不知道为什么; http://acm.hdu.edu.cn/showproblem.php?pid=1754 阅读全文
posted @ 2019-05-06 21:04 starve_to_death 阅读(129) 评论(0) 推荐(0)
摘要:不开longlong见祖宗 题目没说操作中的a,b大小要注意 接着就是状压+线段树 http://poj.org/problem?id=2777 阅读全文
posted @ 2019-05-06 18:24 starve_to_death 阅读(124) 评论(0) 推荐(0)
摘要:区间修改&&单点查询(树状数组) #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<vector> #include<list> #include<ma 阅读全文
posted @ 2019-05-06 16:27 starve_to_death 阅读(178) 评论(0) 推荐(0)