摘要:经典的线段树有空写一下代码。intlMax;//包含结点左端点的最长连续递增子序列的长度intrMax;//包含结点右端点的最长连续递增子序列的长度intMax;//当前结点的最长连续递增子序列的长度intlVal,rVal;//当前结点管辖的区间左右端点的数值intl,r;//当前结点管辖的区间
阅读全文
摘要:诡异的线段树经典题意:给出一个长度为N(N<=30000)的数列,然后是一连串询问,询问数<=100000,问给定区间内不同数字的和。
阅读全文
摘要:代码:#include<iostream>#include<fstream>using namespace std;struct e{ int l,r; bool isa;};e tree[80001];int n;struct f{ int num,s,l;};f b[20001];int c[10001][2];int cmp(const void *a,const void *b){ f *s=(f*)a; f *t=(f*)b; return s->l-t->l;}void build(int s,int t,int p){ tree[p].l=s;
阅读全文
摘要:代码:#include<iostream>#include<fstream>using namespace std;struct e{ int l,r,cnt,cntl,cntr; int state;};e tree[48001];int n,m;void build(int s,int t,int p){ int i,j,k; tree[p].l=s;tree[p].r=t; tree[p].state=-1; tree[p].cnt=tree[p].cntl=tree[p].cntr=t-s+1; if(s==t) return; else { k=(s+t)&g
阅读全文
摘要:代码:#include<iostream>#include<fstream>using namespace std;int n,m,c;struct e{ int l,r; int state; bool id;};e tree[300001];void build(int s,int t,int p){ int i,j,k; tree[p].l=s; tree[p].r=t; if(s==t) return; k=(s+t)>>1; build(s,k,p*2); build(k+1,t,2*p+1);}void update(int s,int t,in
阅读全文
摘要:线段树代码:#include<iostream>#include<fstream>using namespace std;int n,m;struct e{ int l,r,max,maxl,maxr;};e tree[300001];int b[100001];void build(int s,int t,int p){ int i,j,k; tree[p].l=s; tree[p].r=t; if(s==t) { tree[p].max=tree[p].maxl=tree[p].maxr=1; return; } k=(s+t)>>1; build(s,
阅读全文
摘要:线段树,详见陈宏的论文。简单讲就是每两次覆盖之间的差值的总和。代码:#include<iostream>#include<fstream>#include<cmath>using namespace std;struct e{ int l,r,conut,size;}tree[5000*8];int a[20001];int b[20001];int a1[10001];int b1[10001];int n;struct xxx{ int s,t,f,x;}xx[10001];struct yyy{ int s,t,f,y;}yy[10001];void
阅读全文
摘要:线段树,先离散化,再线段树。#include<iostream>#include<fstream>using namespace std;int x[10001],y[10001];int h[20001];int a[10000001];int v[10001];int cmp(const void *a,const void *b){ return *((int*)a)-*((int *)b);}struct e{ int l,r,color;}tree[80001];int n;void build(int l,int r,int p){ tree[p].l=l;
阅读全文
摘要:线段树/** 思路:在线段树的结点内设5个变量l、r、mx、lf、rf,[l,r]表示该结点的区间范围,* lf和rf分别表示元素a[l]和a[r]在区间内的出现频率,mx表示区间内的最高出现频率。* 假设区间[x,y]和[y+1,z]均被询问[i,j]覆盖,则可以分情况讨论区间[x,z]的mx值:* 若a[y]==a[y+1],则mx[x,y]=max{mx[x,y],mx[y+1,z],rf[x,y]+lf[y+1,z]}* 否则mx[x,y]=max{mx[x,y],mx[y+1,z]}**/代码:#include<iostream>#include<fstream&g
阅读全文
摘要:经典线段树,大彻大悟了!!!代码:#include<iostream>#include<fstream>using namespace std;struct e{ int left,right; long long add; long long sum;};e tree[400011];long long a[100001];long long build(int s,int t,int num){ long long i,j; tree[num].left=s; tree[num].right=t; tree[num].add=0; if(s!=t) { i=buil
阅读全文
摘要:线段树题。代码:#include<iostream>#include<fstream>using namespace std;struct e{ int l,r; int color;} tree[800001];int n,m,t;int v[31];void build(int s,int t,int p){ tree[p].l=s; tree[p].r=t; tree[p].color=1; if(t>s) { int mid=(s+t)>>1; build(s,mid,p*2); build(mid+1,t,p*2+1); }}void ins
阅读全文
摘要:线段树题注意思想。代码:#include<iostream>#include<fstream>using namespace std;struct e{ int l,r; int cn;}tree[70000];int level[15001];int n;int x[15001],y[15001];int maxx;void build(int l,int r,int p){ tree[p].l=l; tree[p].r=r; tree[p].cn=0; if(l<r) { int mid=(l+r)>>1; build(l,mid,p*2); bu
阅读全文