zoukankan      html  css  js  c++  java
  • Note -「virtual tree」shorter vrt

    Part. 1 Preface

    没什么 preface。

    Part. 2 实现

    具体来说就是把所有关键点按 ( ext{dfn}) 排序,去重,然后求出相邻结点的 ( ext{LCA}),然后加入关键点,去重;然后把关键点和加入的 ( ext{LCA}) 一起按 ( ext{dfn}) 排序,最后把两两之间的 ( ext{LCA}) 拿出来当爸爸然后把右边当儿子。

    草说不清楚自己看代码,比传统维护右链代码不知道短到哪里去了。

    struct VirtualTree
    {
    	vector<int> e[1000010]; // 连出来的虚树
    	vector<int> build(vector<int> poi) // poi:关键点
    	{
    		sort(poi.begin(),poi.end(),cmp);
    		poi.erase(unique(poi.begin(),poi.end()),poi.end());
    		int len=poi.size();
    		for(int i=0;i<len-1;++i)	poi.push_back(LCA(poi[i],poi[i+1]));
    		sort(poi.begin(),poi.end(),cmp);
    		poi.erase(unique(poi.begin(),poi.end()),poi.end());
    		len=poi.size();
    		for(int i=1;i<len;++i)	e[LCA(poi[i-1],poi[i])].push_back(poi[i]);
    		return poi;
    	}
    }VRT;
    
  • 相关阅读:
    Ajax跨域解决实例
    关于tween.js测试介绍
    signal() 和 sigaction()
    信号概述
    监控文件事件
    栈和栈帧
    进程结构和内存布局
    关于文件I/o的原子操作
    查询Linux系统中glibc的版本
    IOPS和Throughput
  • 原文地址:https://www.cnblogs.com/orchid-any/p/14471100.html
Copyright © 2011-2022 走看看