Table of Contents

ExplanationImplementation
本课程尚无中文翻译,以下显示英文原文。

Official Editorial (C++, Java)

Explanation

This problem is a classic implementation of Heavy Light Decomposition.

Implementation

Time Complexity: O(log2N)\mathcal{O}(\log^2N) per query

#include <bits/stdc++.h>
using namespace std;
Code Snippet: Lazy Segment Tree (Click to expand)
Code Snippet: HLD (Click to expand)
int main() {
int n, q;