2013年8月5日
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=4006直接用SBT中的get_max_Kth函数#include #include #include #include using namespace std;#define LL long longconst int maxn = 100010;#define ls T[x].l#define rs T[x].r#define lls T[ls].l#define lrs T[ls].r#define rls T[rs].l#define rrs T[rs].rstruct SBT{ //左子树指针,右子树 阅读全文
posted @ 2013-08-05 22:27 tobec 阅读(195) 评论(0) 推荐(0) 编辑
摘要: 维护一个集合,插入与删除操作,每一步结束之后,输出中位数#include #include #include #include using namespace std;#define LL long longconst int maxn = 100010;#define ls T[x].l#define rs T[x].r#define lls T[ls].l#define lrs T[ls].r#define rls T[rs].l#define rrs T[rs].rstruct SBT{ //左子树指针,右子树指针,大小,键值 int l,r,sz,key; void init(){ . 阅读全文
posted @ 2013-08-05 18:27 tobec 阅读(169) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=3473对于xl,xl+1……xr,使得[xi-x]和最小,显然x应当为其中的中位数。中位数可以通过求K大数解决,划分树可搞。对于求和,分为两部分,小于x的部分,大于y的部分,在建树的时候也保存下来分到左子树中的数的和。最终的和为ave*(lnum-rnum)+rsum-lsumave为中位数,lnum为左子数的数量,也就是小于中位数的数量,rnum为右子数,lsum表示小于中位数部分的和#include #include #include #include using namespace std;#defin 阅读全文
posted @ 2013-08-05 10:54 tobec 阅读(251) 评论(0) 推荐(0) 编辑