Splay
Loi_a
这个作者很懒,什么都没留下…
展开
-
平衡树
#include<iostream> #include<cstdio> #include<map> using namespace std; map<int,int> bh; int key[100010]; int fa[100010]; int ch[100010][2]; int sz[100010]; int cnt[100010]; int t1,t2,tot,root; int inf=原创 2016-04-15 08:17:25 · 444 阅读 · 0 评论 -
应该没有大问题(坑)
int key[100005]; int fa[100005]; int ch[100005][2]; int root,tot,t1,t2; bool dir(int x) { return x==ch[fa[x]][1]; } void rotate(int x) { bool b=dir(x); int y=fa[x]; int z=fa[y],a=ch[x][原创 2016-07-25 21:58:19 · 433 阅读 · 0 评论 -
bzoj 2733 永无乡 Splay 启发式合并
题目大意:n(n<=10w)个点,每个点都有重要度,q(q<=30w)个操作。1.每次连接2个点。2.查询a,k;与a相连的第k重要是哪一个点,不存在输出-1。 查询可以Splay搞,修改暴力启发式合并,因为每次合并size翻倍,所以每个点最多被合并logn次。复杂度nlog²n。#include<cstdio> #include<iostream> #include<cstdlib> #defi原创 2016-09-24 15:17:05 · 701 阅读 · 1 评论 -
bzoj1503郁闷的出纳员 Splay
Splay维护插入,删除,由排名找值,裸题。 但是比较坑的一点是最后统计离开人数的时候,刚进来就离开的人是不计入答案的(再次重复我语文不好)。直接上代码。#include<iostream> #include<cstdio> using namespace std; int ch[100005][2]; int fa[100005]; int sz[100005]; int key[100005]原创 2016-07-28 15:24:53 · 377 阅读 · 0 评论 -
bzoj 1208 宠物收养所 Splay
我当时脑子一抽,用map查一个数值的编号,多一个log,貌似不影响AC。#include<iostream> #include<cstdio> #include<map> using namespace std; map<int,int> bh; int fa[80005],ch[80005][2]; int sz[80005],key[80005]; int t1,t2; int inf=2147原创 2016-09-26 17:22:17 · 494 阅读 · 0 评论 -
bzoj 3223 文艺平衡树 Splay
Splay维护区间翻转裸题,但还是调了很长时间。#include<iostream> #include<cstdio> #define maxn 100005 using namespace std; int rev[maxn],fa[maxn],ch[maxn][2]; int sz[maxn]; int root; bool dir(int x) {return x==ch[fa[x]][1];原创 2016-09-29 10:00:32 · 366 阅读 · 0 评论 -
bzoj 3196 二逼平衡树 树套树
都是泪,调了一晚。代码能力++。 查询区间排名k,时间复杂度nlog³n,bzoj能A,但是tyvj TLE 两个点,求各路大神指错打脸。 另外推荐一个OJ cojs.tk 给数据,很良心。#include<iostream> #include<cstdio> #include<algorithm> #include<stack> #define maxn 1000005 //#原创 2016-09-26 21:45:41 · 423 阅读 · 0 评论