hdu 5029树链剖分

/*
解:标记区间端点,按深度标记上+下-。
然后用线段树维护求出最小的,再将它映射回来
*/
#pragma comment(linker, "/STACK:102400000,102400000")
#include
#include
#include
#include
#include
using namespace std;
#define N  100500
struct node {
int u,v,next;
}bian[N*2];
int f[N],top[N],fp[N],siz[N],son[N],fa[N],head[N],yong;
int deep[N],cnt;
vectoradd[N],stra[N];
void init() {
yong=0;cnt=0;
memset(head,-1,sizeof(head));
memset(son,-1,sizeof(son));
}
void addedge(int u,int v) {
 bian[yong].u=u;
 bian[yong].v=v;
 bian[yong].next=head[u];
 head[u]=yong++;
}
void dfs1(int u,int father,int d) {
  deep[u]=d;
  fa[u]=father;
  siz[u]=1;
  int i;
  for(i=head[u];i!=-1;i=bian[i].next) {
    int v=bian[i].v;
    if(v!=father) {
        dfs1(v,u,d+1);
       siz[u]+=siz[v];
       if(son[u]==-1||siz[son[u]]deep[v])
   swap(u,v);
   add[f[u]].push_back(w);
  stra[f[v]].push_back(w);
   return ;
}
struct nodee{
int l,r,node,num;
}tree[N*4];
void pushdown(int t) {
  if(tree[t*2].num>=tree[t*2+1].num) {
    tree[t].num=tree[t*2].num;
    tree[t].node=tree[t*2].node;
  }
  else {
    tree[t].num=tree[t*2+1].num;
    tree[t].node=tree[t*2+1].node;
  }
  return ;
}
void build(int t,int l,int r) {
   tree[t].l=l;
   tree[t].r=r;
   if(l==r){
       // printf("%d\n",l);
    tree[t].node=l;
    tree[t].num=0;
    return ;
   }
   int mid=(l+r)/2;
   build(t*2,l,mid);
   build(t*2+1,mid+1,r);
   pushdown(t);
   return ;
}
void qury(int t,int k,int nu) {
   if(tree[t].l==tree[t].r) {
    tree[t].num+=nu;
   // printf("")
    return ;
   }
   int mid=(tree[t].l+tree[t].r)/2;
   if(k<=mid)
    qury(t*2,k,nu);
   else
    qury(t*2+1,k,nu);
   pushdown(t);
  // printf("%d %d %d\n",tree[t].l,tree[t].r,tree[t].node);
}
int answer[N];
int Max(int v,int vv) {
return v>vv?v:vv;
}
int main() {
   int n,m,i,j,u,v,w,mxx;
   while(scanf("%d%d",&n,&m),n||m) {
    init();
    for(i=1;i

转载于:https://www.cnblogs.com/thefirstfeeling/p/4410582.html

你可能感兴趣的:(hdu 5029树链剖分)