
ACM-树
文章平均质量分 83
kjcsdnblog
新人求罩
展开
-
RMQ和LCA在线算法
原文 学习一下LCA的在线算法。RMQRMQ是查询区间最值的一种方法,其思想非常简单。举例来说,我们想查询区间[5,37][5,37]中的最小值,如果我们事先知道区间[5,5+24)[5,5+2^4)中的最小值以及区间[37−24+1,37+1)[37-2^4+1,37+1)中的最小值,那么我们很容易得到答案。于是问题就变为,我们如何知道区间[i,i+2k)[i,i+2^k)中的最小值。显然Min原创 2017-09-02 00:48:29 · 473 阅读 · 0 评论 -
poj3667线段树
题意:输入n,m; n代表1-n的区间,m代表有m个操作。对于每个操作如果先输入1,则输入w,找到区间最左边未被占用的连续长度为w的区间,返回左端点,并把这段区间标记为已被占用。如果整个区间没有找到符合条件的区间。则返回0.原创 2015-01-20 21:42:54 · 381 阅读 · 0 评论 -
poj 2528 Mayor's posters
离散话和区间修改:#include #include #include #include using namespace std;const int MAXN= 100010;int t[MAXN][2],s[MAXN<<3];struct tree{ int l,r; int color;}a[MAXN<<3];int ans=0;int vis[MAXN原创 2014-11-08 18:31:37 · 304 阅读 · 0 评论 -
poj2352-线段树-start
#include #include #include #define N 32010using namespace std;struct tree{ int l,r; int sum;}a[4*N];void build(int l,int r,int k){ a[k].l=l;a[k].r=r;a[k].sum=0; if(l==r){原创 2014-11-08 18:27:27 · 369 阅读 · 0 评论 -
uva122-Trees on the level
#include #include #include #include #include using namespace std;const int N=260;string str[N];bool ffflag=true;struct Node{ string num; string dir;};bool cmp(Node a,Node b){ i原创 2014-10-31 15:48:07 · 330 阅读 · 0 评论 -
uva536 Tree Recovery
已知前序中序求后序#include #include #include #include using namespace std;string po;void Computing(string pre,string in){ int len=pre.length(); if(len>0){ int p=(int)(in.find(pre[0]));原创 2014-10-29 19:33:38 · 366 阅读 · 0 评论