区间更新是个坎。。。 堆式的区间更新是个大坎。。。
解法1 还没理解自底向上的更新方法, 还是自顶向下的递归更新, 跑了859ms,悲剧。。。
代码很丑, 不过自创了一个debug函数,可以看树的结构, 不错,不错。
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn=100000+123;
int T[maxn*3];
int M, h;
int bit(int x)/// get highest 1 in bit-number
{
if(x==0)return 0;
int n=31;
if((x>>16)==0){n-=16; x<<=16;}
if((x>>24)==0){n-=8; x<<=8;}
if((x>>28)==0){n-=4; x<<=4;}
if((x>>30)==0){n-=2; x<<=2;}
return n-(x>>31);
}
inline void merge (const int &x)//合并2个儿子的信息
{
if(T[x]==0 && T[x<<1]==T[x<<1|1])T[x]=T[x<<1];
}
void init(const int & x)
{
h=bit(x);
M=1<<h;
memset (T, 0, sizeof(T));
for (int i=M; i<x+M; ++i)
T[i]=1;
for (int i=M-1; i>0; --i)
merge(i);
}
void Updata(int x, int v)
{
T[x]=v;
if(x<M)
{
T[x<<1]=v;
T[x<<1|1]=v;
}
}
void color (int l, int r, int x, int root)
{
if(T[root]==x)return ;
if(root>M+M)return;
if(root>=M){if(root>l && root<r)T[root]=x; return;}
int t=h-bit(root)+1;
if((l>>t)<root && (r>>t)>root)
T[root]=x;
else
{
if(T[root]){T[root<<1]=T[root]; T[root<<1|1]=T[root]; T[root]=0;}
if((l>>(t-1))<=(root<<1))color(l, r, x, root<<1);
if((r>>(t-1))>=(root<<1|1))color(l, r, x, root<<1|1);
}
}
inline void Change(int l, i