随笔分类 -  数据结构

摘要:Trie树。 要求字典序最小,所以由前到后贪心的选择。建一个trie树维护b数列。 #include #include #include using namespace std; const int maxn = 300000*(20+5) ; const int maxm = 30 + 10; int a[maxn],s[maxn],p0[maxn],p1[maxn],cnt; in... 阅读全文
posted @ 2018-03-25 19:31 invoid 阅读(227) 评论(0) 推荐(0)
摘要:权值线段树。 要求 L #include #include #define LL long long using namespace std; const LL inf = 10000000000ll; const int maxn = 100000 + 10; const int maxm = 8000000 + 10; struct segtree { LL l[maxm],r[... 阅读全文
posted @ 2016-07-11 17:11 invoid 阅读(383) 评论(0) 推荐(0)
摘要:树分治。 网上有部分人的题解写的啥呀。。。 按重心进行分治。 首先O(n)算出以当前点为根depth(u)+depth(v) #include #include using namespace std; const int maxn = 10000 + 10; const int maxm = 20000 + 10; const int inf = 0x3f3f3f3f; int g[max... 阅读全文
posted @ 2016-07-08 16:23 invoid 阅读(121) 评论(0) 推荐(0)
摘要:斜率优化+树分治。 点分治:找出当前子树的重心,分治根到重心这一段,更新根到重心这一段的值,将剩下的点按能到达的高度从低到高排序,更新。分治其他子树。 阅读全文
posted @ 2016-07-05 11:45 invoid 阅读(153) 评论(0) 推荐(0)
摘要:LCT. 将边按a从小到大排序后不断往进加,出现环就把b最大的边去除掉。 lct中边也要单独建一个节点保存边权。 #include #include #include using namespace std; const int maxn = 200000 + 10; const int maxm = 800000 + 10; const int inf = 0x7f7f7f7f; ... 阅读全文
posted @ 2016-07-04 14:15 invoid 阅读(151) 评论(0) 推荐(0)
摘要:仙人掌。 仙人掌入门题。。不过入门都好难。。。 题解好复杂。。 总体来说,没有环的话,就是一棵树,很好求。 如果有环的话,就找出这个环,用一个单调队列用环上俩个点对更新答案。(如果不用单调队列就O(n^2)超时) #include #include #include using namespace std; const int maxn = 3000000 + 10; in... 阅读全文
posted @ 2016-07-01 18:18 invoid 阅读(191) 评论(0) 推荐(0)
摘要:线段树。 真还就是个线段树。。 除去操作1,2的话,线段树很容易就处理了,问题在于如何处理操作1和2。(这点没想到)。。 我们用一个delta维护操作1,如果没有旋转就+k,不然就-k。 每次读入i和j的时候用trans处理一下,就成功在O(1)的时间解决了操作1和2。 细节很重要。 #include #include #include using namespace std; ... 阅读全文
posted @ 2016-07-01 16:45 invoid 阅读(141) 评论(0) 推荐(0)
摘要:树链剖分。 这道题就写个dfs序,乱搞一下就过了。 简单型的树剖 #include #include #include using namespace std; const int maxn = 200000 + 10; const int maxm = 400000 + 10; int g[maxn],v[maxm],next[maxm],eid; int size[maxn],so... 阅读全文
posted @ 2016-06-30 18:13 invoid 阅读(398) 评论(0) 推荐(0)
摘要:dfs序+线段树. 首先生成树的出栈入栈序。 然后入栈设为a[u],出栈设为-a[u]。 子树在线段树上是一个连续的范围,所以三个操作都可以在线段树上实现了。 ps:val设成int,wa了无数发。。 #include #include #include #include using namespace std; typedef long long LL; const int... 阅读全文
posted @ 2016-06-29 10:29 invoid 阅读(141) 评论(0) 推荐(0)
摘要:树状数组,离线处理。 首先把询问按左端点的大小升序排序。 从左往右扫描的过程中,将一个颜色第一次出现的位置变为0,第二次出现的位置变为1. #include #include #include using namespace std; const int maxn = 1000000 + 10; struct Query { int l,r,id; }q[maxn]; st... 阅读全文
posted @ 2016-06-14 20:10 invoid 阅读(185) 评论(0) 推荐(0)
摘要:线段树维护联通性。 题目下方有分析。 题解里面说的行数等于题目中的行数-1. 经过分析一共(r1,c1)->(r2,c2)一共有四种方式。 假设r1=1,r2=0。 1.直接过去。 2.先到(0,c1)再过去。 3.先到(1,c2)再过去。 4.先到(0,c1)再到(1,c2)再过去。 用一个数组a 阅读全文
posted @ 2016-06-14 15:19 invoid 阅读(1239) 评论(1) 推荐(0)