The article discusses the Chtholly Tree, a powerful and efficient data structure invented by Ghost_Dragon on Codeforces. The Chtholly Tree is particularly useful for interval assignment operations and random data, and it has a complexity of O(n log log n) with random data. The article provides code snippets to demonstrate its use cases and links to the original blogs and relevant resources. The conclusion emphasizes the Chtholly Tree's potential to simplify many interval-related problems. Ghost_Dragon, the inventor of the Chtholly Tree, is briefly introduced as a competitive programmer with a strong track record on Codeforces.
The Chtholly Tree, invented by Ghost_Dragon, is a powerful brute force data structure for interval assignment operations on random data. Although it is not actually a tree data structure, it is often used with std::set, which is implemented as a red-black tree.
The Chtholly Tree is especially useful for problems involving interval assignment operations and random data. It has a time complexity of O(n log log n) with random data, making it a highly efficient solution for a wide range of competitive programming problems.
To learn more about the Chtholly Tree and its implementation, check out Ghost_Dragon's original blog post here. You can also find additional resources and code snippets on the topic by searching for "Chtholly Tree" on Codeforces.
Here's an example of how to use the Chtholly Tree in your code:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
struct chtholly {
int l, r, val;
} t[N * 50];
int root[N], cnt;
void build(int &u, int l, int r) {
u = ++cnt;
if (l == r) return;
int mid = (l + r) >> 1;
build(t[u].l, l, mid);
build(t[u].r, mid + 1, r);
}
void modify(int &u, int &v, int l, int r, int x, int k) {
u = ++cnt;
t[u] = t[v];
t[u].val += k;
if (l == r) return;
int mid = (l + r) >> 1;
if (x <= mid) modify(t[u].l, t[v].l, l, mid, x, k);
else modify(t[u].r, t[v].r, mid + 1, r, x, k);
}
int query(int u, int v, int l, int r, int k) {
if (l == r) return l;
int mid = (l + r) >> 1, sum = t[t[u].l].val - t[t[v].l].val;
if (sum >= k) return query(t[u].l, t[v].l, l, mid, k);
else return query(t[u].r, t[v].r, mid + 1, r, k - sum);
}
int main() {
int n;
cin >> n;
build(root[0], 1, n);
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
modify(root[i], root[i - 1], 1, n, x, 1);
}
int m;
cin >> m;
while (m--) {
int l, r, k;
cin >> l >> r >> k;
cout << query(root[r], root[l - 1], 1, n, k) << endl;
}
return 0;
}
In this example, the Chtholly Tree is used to efficiently solve a problem involving interval assignment operations. The build
, modify
, and query
functions are implemented to construct and update the Chtholly Tree, while the main
function uses the Chtholly Tree to solve the problem.
Overall, the Chtholly Tree is a powerful and efficient data structure that can greatly simplify many interval assignment problems with random data. Its unique design allows for quick and easy updates and queries, making it an ideal choice for many competitive programming problems. Its creator, Ghost_Dragon, has provided detailed explanations and examples in their original blog posts, making it accessible for anyone to implement and utilize in their own coding projects. If you're looking to optimize your interval assignment operations, the Chtholly Tree is definitely worth considering.