随笔分类 -  线段树+字典树+树状数组+树链剖分+树的分治

1
摘要:转载:http://blog.csdn.net/qinzhenhua100/article/details/39716851二种操作,一种更新结点值,一种更新路径值,最后输出更改后的结点值和路径值。对于区间[a,b],区间的每个值加上c,可以用一个数组标记,ans[a]+=c,ans[b+1]-=c... 阅读全文
posted @ 2014-10-10 16:30 HYDhyd 阅读(119) 评论(0) 推荐(0)
摘要:/*解:标记区间端点,按深度标记上+下-。然后用线段树维护求出最小的,再将它映射回来*/#pragma comment(linker, "/STACK:102400000,102400000")#include#include#include#include#includeusing namespa... 阅读全文
posted @ 2014-10-10 10:44 HYDhyd 阅读(114) 评论(0) 推荐(0)
摘要:/*题意:给你一些节点和一些边,求最短路径树上是k个节点的最长的路径数。解:1、求出最短路径树--spfa加记录 2、树上进行操作--树的分治,分别处理子树进行补集等运算*/#include#include#include#include#include#include#define ll _... 阅读全文
posted @ 2014-10-04 17:14 HYDhyd 阅读(141) 评论(0) 推荐(0)
摘要:/*树的分治因为树的点权值可达到10^15,注意手动扩栈,还有int64题意:给你一棵树,给你一些素数,给你每个点一个权值且每个权值均可由这些素数组成。现在定义任意任意两点的价值为他们路径上的权值相乘。求这样的点对的权值为立方数的个数解:如果直接求得话会超int64,不可行由立方数的性质可得,一个数... 阅读全文
posted @ 2014-10-02 20:03 HYDhyd 阅读(283) 评论(0) 推荐(0)
摘要:/*啊啊啊啊啊啊啊本题证明一个问题,在实际应用中sort比qsort块还有memset这类初始化能不加尽量别加,很浪费时间原来的程序把qsort该成sort,去掉一个无用memset就a了时间不到一半题意:和poj1741差不多,不过本题求的是dis[i]+dis[j]==dis[k];*/#inc... 阅读全文
posted @ 2014-10-01 20:00 HYDhyd 阅读(184) 评论(0) 推荐(0)
摘要:/*树的分治题意:求树上两点间的距离#include#include#define N 11000#define inf 0x3fffffffstruct node{int u,v,w,next;}bian[N*4];int head[N],yong,num[N],ma,minn,m,nn,vis... 阅读全文
posted @ 2014-10-01 16:39 HYDhyd 阅读(125) 评论(0) 推荐(0)
摘要:树的重心定义为:找到一个点,其所有的子树中最大的子树节点数最少,那么这个点就是这棵树的重心,删去重心后,生成的多棵树尽可能平衡. 实际上树的重心在树的点分治中有重要的作用, 可以避免N^2的极端复杂度(从退化链的一端出发),保证NlogN的复杂度, 利用树型dp可以很好地求树的重心/*求树的重心,... 阅读全文
posted @ 2014-10-01 14:36 HYDhyd 阅读(196) 评论(0) 推荐(0)
摘要:转载地址:http://blog.csdn.net/pi9nc/article/details/12394117主要是利用了反证法:假设 s-t这条路径为树的直径,或者称为树上的最长路现有结论,从任意一点u出发搜到的最远的点一定是s、t中的一点,然后在从这个最远点开始搜,就可以搜到另一个最长路的端点... 阅读全文
posted @ 2014-09-30 16:56 HYDhyd 阅读(281) 评论(0) 推荐(0)
摘要:/*树链刨分+离线操作题意:给你一棵树,和询问x,y 从节点x--节点1的小于等于y的最大值. 解:先建一个空树,将树的边权值从小到大排序,将询问y按从小到大排序 对于每次询问y将小于等于y的边权值的边加入,在进行询问将结果储存最后输出即可 易错点:要考虑到节点1到节点1的情况需特判。*/#... 阅读全文
posted @ 2014-09-30 15:49 HYDhyd 阅读(198) 评论(0) 推荐(0)
摘要:/*本体在spoj375的基础上加了一些操作,用到线段树的lazy操作模板类型*/#include#include#include#include#include#include#includeusing namespace std;#define N 11000#define inf 0x3ff... 阅读全文
posted @ 2014-09-29 16:25 HYDhyd 阅读(170) 评论(0) 推荐(0)
摘要:/*只是一道树链刨分的入门题,作为模板用。*/#include#include#include#include#include#include#includeusing namespace std;#define N 11000#define inf 0x3fffffffint head[N];i... 阅读全文
posted @ 2014-09-29 15:52 HYDhyd 阅读(164) 评论(0) 推荐(0)
摘要:/*线段树延迟更新+状态压缩*/#include#define N 1100000struct node { int x,y,yanchi,sum;}a[N*4];int lower[31];void build(int t,int x,int y) {a[t].x=x;a[t].y=y;a[t]... 阅读全文
posted @ 2014-09-22 15:27 HYDhyd 阅读(92) 评论(0) 推荐(0)
摘要:656mS#include#include#define N 110000struct node {int x,y,yanchi,sum;}a[N*10];void build(int t,int x,int y) {a[t].x=x;a[t].y=y;a[t].sum=0;a[t].yanchi=... 阅读全文
posted @ 2014-05-21 21:25 HYDhyd 阅读(156) 评论(0) 推荐(0)
摘要:#include#include#define N 51000char s[N];int a[N],n;int number(int x) {return x&-x;}void creat(int x,int k) {int i;for(i=x;i=1;i-=number(i))su+=a[i];r... 阅读全文
posted @ 2014-03-25 14:45 HYDhyd 阅读(98) 评论(0) 推荐(0)
摘要:二维树状数组 单点更新区间查询 模板从零开始借鉴http://www.2cto.com/kf/201307/227488.html#include#include#define N 1100int c[N][N],visit[N][N],n;int number(int x) {return x&-... 阅读全文
posted @ 2013-11-19 21:00 HYDhyd 阅读(113) 评论(0) 推荐(0)
摘要:#include#include#define N 51000int c[N],n;int number(int x) {return x&-x;}void creat(int a,int x) {int i;for(i=a;i0;i-=number(i)) h+=c[i];return h;}... 阅读全文
posted @ 2013-11-19 20:42 HYDhyd 阅读(101) 评论(0) 推荐(0)
摘要:#include#includestruct node {int num,i;node *a[27];char s[20];//定义局部不是空的node() {num=0;for(i=0;ia[s1[i]-'a']==NULL)root->a[s1[i]-'a']=new node();root=r... 阅读全文
posted @ 2013-11-18 17:07 HYDhyd 阅读(139) 评论(0) 推荐(0)
摘要:#include#include#includeusing namespace std;struct node {int num,i;node *a[27];node (){num=0;for(i=0;ia[str[i]-'a']==NULL) {q=new node();q->num++;root... 阅读全文
posted @ 2013-11-17 16:41 HYDhyd 阅读(98) 评论(0) 推荐(0)
摘要:个人觉得这个模板比较好http://www.tuicool.com/articles/6Fv2Ej模仿这个模板我写的poj上的2001#include#include#includeusing namespace std;struct node {int num;node *a[27]; node... 阅读全文
posted @ 2013-11-17 16:18 HYDhyd 阅读(159) 评论(0) 推荐(0)
摘要:#include#include#includeusing namespace std;struct trie {trie *a[27];int v;}*h,*t;int len,k;char str[1100][30];void build(int count,trie *h) {int i,j;... 阅读全文
posted @ 2013-11-17 15:37 HYDhyd 阅读(156) 评论(0) 推荐(0)

1