随笔分类 - acm 线段树
摘要:充分利用下标的资源,tree[]表示节点含有的数据个数#include <stdio.h>const int MAXN=262144;int tree[MAXN<<1];int pos;void build(int l,int r,int rt){ tree[rt]=r-l+1;//表示节点含有的数据个数 if(r==l) return ; int m=(r+l)/2; build(l,m,rt*2); build(m+1,r,rt*2+1);}void update(int p,int l,int r,int rt){ tree[rt]--;//更新节点的数的个数 i
阅读全文
摘要:染色插入算法procedure Insert(p, l, r, a, b, c: Integer);var m: Integer;begin if Tree[p].cover <> c then begin m := (l + r) div 2; if (a = l) and (b = r) then Tree[p].cover := c else begin if Tree[p].cover >= 0 then begin Tree[p * 2].cover := Tree[p].cover; Tree[p * 2 + 1].cover := Tree[p].cover;
阅读全文
摘要:其中的标志s用的很妙,非常精髓,标记是否是纯色,单色,是否往下递归,计算单色数据#include <iostream>#include <cstdio>using namespace std;const int MAXN=2000000;int n,m,a[MAXN+5],ans;struct tree{ int l,r; int s;}trees[MAXN*2];int max(int k,int l){ return k>l?k:l;}void buildtree(int rs,int l,int r){ //printf("%d %d %d\n&q
阅读全文
摘要:#include <iostream>#include <cstdio>using namespace std;const int MAXN=2000000;int n,m,a[MAXN+5];struct tree{ int l,r; int v;}trees[MAXN*2];int max(int k,int l){ return k>l?k:l;}void buildtree(int rs,int l,int r){ //printf("%d %d %d\n",rs,l,r); trees[rs].l=l; trees[rs].r=r;
阅读全文
摘要:越来越感觉算法就是一种方法,一个解决一类问题的公式,当然公式有变形,题也有变形但只要深刻理解它,变形只是一种顺理而成,只要类比公式,推理一下,将代码变形一下#include <stdio.h>#include <string.h>#define MAX 50005struct trea{ int l,r; int summ;}trees[MAX*3];int num[MAX],n,t;void biuld(int i,int l,int r){ trees[i].l=l; trees[i].r=r; if(l==r) { trees[i].summ=num[l-1];
阅读全文

浙公网安备 33010602011771号