This repository has been archived on 2022-06-22. You can view files and clone it, but cannot push or open issues or pull requests.
usaco-guide/content/6_Plat/Seg_Ext.mdx
2020-06-27 22:11:09 -04:00

74 lines
2.3 KiB
Text

---
id: seg-ext
title: "More Applications of Segment Tree"
author: Benjamin Qi
prerequisites:
- Gold - Static Range Queries
- Gold - Point Update Range Query
description: "?"
frequency: 3
---
import { Problem } from "../models";
export const metadata = {
problems: {
walkSam: [
new Problem("CSES", "Hotel Queries", "1143", "Easy", false, ["PURQ"], "walk"),
],
walk: [
new Problem("Old Gold", "Seating", "231", "Normal", false, [], "walk on max segtree"),
new Problem("Plat", "Balancing", "624", "Normal", false, [], "walk"),
],
combSam: [
new Problem("CSES", "Subarray Sum Queries", "1190", "Normal", false, ["PURQ"], "comb"),
],
comb: [
new Problem("Plat", "High Card Low Card", "577", "Normal", false, ["PURQ", "Greedy"], "comb"),
new Problem("POI", "Cards", "https://szkopul.edu.pl/problemset/problem/qpsk3ygf8MU7D_1Es0oc_xd8/site/?key=statement", "Normal", false, [], "comb"),
new Problem("Old Gold", "Marathon", "495", "Normal", false, [], "comb"),
new Problem("Old Gold", "Optimal Milking", "365", "Normal", false, [], "comb"),
],
waveletSam: [
new Problem("YS", "Range K-th Smallest", "range_kth_smallest", "Hard", false, ["Wavelet"], ""),
],
wavelet: [
new Problem("Kattis", "Easy Query", "easyquery", "Hard", false, ["Wavelet"], ""),
new Problem("DMOJ", "Ninjaclasher's Wrath 2", "globexcup19s4", "Hard", false, ["Wavelet"], ""),
],
}
};
## Walking on a Segment Tree
<problems-list problems={metadata.problems.walkSam} />
You want to support queries of the following form on an array $a_1,\ldots,a_N$ (along with point updates).
> Find the first $i$ such that $a_i\ge x$.
Of course, you can do this in $O(\log^2N)$ time with a max segment tree and binary searching on the first $i$ such that $\max(a_1,\ldots,a_i)\ge x$. But try to do this in $O(\log N)$ time.
<problems-list problems={metadata.problems.walk} />
## Combining
<problems-list problems={metadata.problems.combSam} />
(solution to above problem)
<problems-list problems={metadata.problems.comb} />
## Wavelet Tree
<problems-list problems={metadata.problems.waveletSam} />
### Tutorial
<resources>
<resource source="CF" title="Intro to New DS: Wavelet Trees" url="blog/entry/52854"></resource>
</resources>
### Problems
<problems-list problems={metadata.problems.wavelet} />