树上启发式合并
_leon1999
qaq
展开
-
树上启发式合并
补题时碰见的骚操作。可以在nlogn的时间内处理一些没有修改的,对子树的查询问题。具体方法为1.轻重链剖分,找出重儿子。(预处理)2.先处理轻儿子,不记录 贡献。3.处理重儿子,记录贡献。4.将当前节点和轻儿子的贡献和重儿子合并。5.如果当前节点是轻儿子的话,消除影响。算法的正确性很容易理解。重儿子不用清空了, 因为我的兄弟节点都已经处理完了,我不会影响到兄弟节点...原创 2019-03-22 11:02:23 · 254 阅读 · 0 评论 -
CodeForces - 570D Tree Requests (树上启发式合并)
CodeForces - 570D题目大意:给出一个节点u问,节点u的子树中在深度为h的节点能不能组成一个回文串。解题思路:寒假训练赛的一个题目,当时也不会,补题的时候用dfs序+二分写的。后来发现能用启发式合并写。当时二分差点挂了,果然树上启发式合并跑的飞快。。。。#include<bits/stdc++.h>using namespace std;#defi...原创 2019-03-22 11:44:03 · 199 阅读 · 0 评论 -
Acyclic Organic Compounds dsu
D. Acyclic Organic Compoundstime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a treeTwithnvertices (numbered1t...原创 2019-07-23 19:18:21 · 126 阅读 · 0 评论 -
Codeforce E - Lomsat gelral (dsu on the tree)
E. Lomsat gelraltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a rooted tree with root in vertex1. Each vertex i...原创 2019-07-28 11:04:18 · 139 阅读 · 0 评论