随笔分类 -  segment tree

摘要:View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 50003#define lson l, m, rt<<1#define rson m+1, r, rt<<1|1#define mid int m = (l + r)>>1int col[maxn<<2];int lsum[maxn<<2], msum[maxn<<2], rsum[maxn&l 阅读全文
posted @ 2012-11-24 19:43 To be an ACMan 阅读(164) 评论(0) 推荐(0)
摘要:View Code #include<stdio.h>#include<string.h>#include<algorithm>#include<vector>using namespace std;const int maxn = 8000<<1;#define lson l, m, rt<<1#define rson m+1, r, rt<<1|1#define mid int m = (l + r)>>1int n;int col[maxn<<2];int vis[maxn< 阅读全文
posted @ 2012-11-24 18:15 To be an ACMan 阅读(192) 评论(0) 推荐(0)
摘要:View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxn = 65666<<1;#define lson l, m, rt<<1#define rson m+1, r, rt<<1|1#define mid int m = (l + r) >> 1int col[maxn<<2], XOR[maxn<<2];bool vis[maxn<< 阅读全文
posted @ 2012-11-24 15:06 To be an ACMan 阅读(184) 评论(0) 推荐(0)
摘要:注意离散化View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define lson l, m, rt<<1#define rson m+1, r, rt<<1|1#define mid int m = (l + r)>>1#define maxn 10004int col[maxn<<4];int l[maxn], r[maxn];int a[maxn<<4], m, n;int 阅读全文
posted @ 2012-11-24 12:52 To be an ACMan 阅读(207) 评论(0) 推荐(0)
摘要:题意:给出一个长度为N(N <= 100000)的数列,然后是两种操作:U A B: 将第A个数替换为B (下标从零开始)Q A B: 输出区间[A, B]的最长连续递增子序列询问的次数m <= 100000。类型:区间合并这题跟POJ hotel差不多,这题应该比hotel简单一些,因为 update是单点更新,所以每次更新数据都是更新到低的,所以不用写pushdown函数,pushup里面比hotel多了一个判断,即num[m] < num[m]时左右儿子的数据才能合并,否则不合并,其它跟hotel无差。View Code #include<stdio.h># 阅读全文
posted @ 2012-08-24 15:58 To be an ACMan 阅读(399) 评论(0) 推荐(0)
摘要:代码风格:notonlysuccess。单点更新:最最基础的线段树,只更新叶子节点,然后把信息用PushUP(int r)这个函数更新上来。很基础的,notonlysuccess里面有的, 先学学它里面的吧。网站: http://www.notonlysuccess.com/index.php/segment-tree-complete/以下是notonlysuccess里没有的1. POJ 2828 Buy Tickets题意:插队问题.关键:如何将这些人插入队伍中去。类型:单点更新思路:人要逆着插入队伍, 最先插入的一个数据的位置明显是题目给定的位置,可以确定,然后插入的几个人的位置前面插 阅读全文
posted @ 2012-08-24 10:07 To be an ACMan 阅读(1571) 评论(0) 推荐(2)
摘要:题意:在墙上贴海报,海报可以互相覆盖,问最后可以看见几张海报思路:这题数据范围很大,直接搞超时+超内存,需要离散化:离散化简单的来说就是只取我们需要的值来用,比如说区间[1000,2000],[1990,2012] 我们用不到[-∞,999][1001,1989][1991,1999][2001,2011][2013,+∞]这些值,所以我只需要1000,1990,2000,2012就够了,将其分别映射到0,1,2,3,在于复杂度就大大的降下来了所以离散化要保存所有需要用到的值,排序后,分别映射到1~n,这样复杂度就会小很多很多而这题的难点在于每个数字其实表示的是一个单位长度(并非一个点),这样 阅读全文
posted @ 2012-07-11 19:26 To be an ACMan 阅读(149) 评论(0) 推荐(0)
摘要:POJ2828 Buy Tickets题意:插队问题;关键:如何插入这几个节点,每个节点储存什么信息。类型:很基本的单点更新线段树思路:这题想到了就水了,数据逆着插入,最先插入的一个数据的位置明显是题目给定的位置,可以确定,然后插入的几个数根据的位置前面插入的数据来决定,用sum[]数组表示改线段空位置的个数,满足 pos<=sum[rt<<1](即左儿子的空位多于插入数的位置序号)就访问左儿子,否则访问右儿子(访问右节点的时候注意pos要修改,改为pos-sum[rt],即整个线段的第pos个空位,在下一个右儿子那的第pos-sum[rt]个空位)。对自己的总结: 刚学线段 阅读全文
posted @ 2012-07-11 18:29 To be an ACMan 阅读(3626) 评论(0) 推荐(1)
摘要:向这位努力了一年的大一就进总决赛的大牛学习。线段树专辑大全进入它的博客后 在右边推荐文章里点《完全版线段树》注意有些浏览器打不开这个网站,据我所知,谷歌浏览器,搜狗浏览器 可以用。大牛博客:www.notonlysuccess.com 阅读全文
posted @ 2012-07-04 22:34 To be an ACMan 阅读(415) 评论(0) 推荐(1)