Two-Dimensional Data Structures for K-th Largest Queries

Problem Overview This problem involves efficiently handling two types of queries on a dynamic collection of elmeents: 1. Insert elements into specified ranges 2. Find the K-th largest value within a specified range We explore several advanced data structure approaches to solve this problem efficiently. ### Binary Indexed Tree with Dynamic Segme ...

Posted on Tue, 01 Sep 2026 16:11:48 +0000 by johnnyblaze9

Efficient Algorithms for Range Queries, Matrix Exponentiation, Trie DFS, and Subset Sum with Modular Arithmetic

Problem T1: Maximum Cross-Shaped Area in a Grid Given a binary grid where '.' represents a valid cell and other characters are blocked, compute the largest cross-shaped region centered at any valid cell. A cross is defined by a vertical segment of height h and a horizontal segment of width w, both centered at the same point, with the total peri ...

Posted on Wed, 26 Aug 2026 16:40:14 +0000 by ricerocket

Solutions to Competitive Programming Problems

Problem A: Graph Coloring We are given an integer n and need to color the integers from 1 to n. The constraint is that for any two integers i and j where i < j, if their difference j - i is a prime number, they must have differant colors. The goal is to use the minimum number of colors possible and provide a valid coloring scheme. For n > ...

Posted on Wed, 19 Aug 2026 16:36:35 +0000 by cool30

Tree-Based Capacity Constraints and Segment Tree Permutation Optimization

The solution to the first problem hinges on a capacity threshold observation regarding subtrees relative to a target node. If the aggregate capacity of all subtrees excluding the target exceeds a specific bound, the second player can guarantee allocating at least half of the operations outside the target subtree. This lower bound is tight when ...

Posted on Fri, 14 Aug 2026 16:43:45 +0000 by Ravrflavr

Segment Tree Implementation for Maximum Subarray Sum Queries

Given an array of n elements arr_1, arr_2, ..., arr_n, support q operations: Type 1: Update arr_x = value Type 2: Query maximum subarray sum in range [l, r] Information to Maintain To solve this problem using divide and conquer, we need to determine what information can be merged to compute the required result. The maximum subarray sum in a r ...

Posted on Wed, 12 Aug 2026 16:32:02 +0000 by ph3n0m

Essential Data Structures and Algorithmic Templates

A classic strcuture for managing dynamic connectivity and equivalence classes. Initialization int parent[N]; void initUnionFind() { for (int i = 1; i <= n; ++i) { parent[i] = i; } } Path Compression Find int findRoot(int x) { return parent[x] == x ? x : parent[x] = findRoot(parent[x]); } Union by Root void unite(int a, ...

Posted on Wed, 12 Aug 2026 16:17:03 +0000 by dibyajyotig

Essential Algorithm Templates for Competitive Programming

Data Structures Segment Tree #include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long ll; const int MAXN = 100010; int n, m; vector<ll> arr; vector<ll> tree; vector<ll> lazy; inline ll read() { ll x = 0, f = 1; char ch = getchar(); while (ch < '0' || ...

Posted on Tue, 28 Jul 2026 16:49:08 +0000 by Daggeth

Chtholly Tree and Color Segment Amortization

Overview The Chtholly Tree, also known as ODT (Old Driver Tree), gained popularity through Codeforces problem 896C. It's crucial to understand that this approach is fundamentally based on color segment amortization for random data, rather than being a strict data structure. The operations described below represent specific implementations of th ...

Posted on Fri, 24 Jul 2026 16:28:49 +0000 by Renich

Persistent Segment Trees: Path Copying for Historical Range Queries

A persistent segment tree maintains a complete history of all structural modifications applied to the data structure. Unlike standard implementations that overwrite previous states, this variant preserves every version, enabling direct queries on historical configurations. The core technique relies on path copying, where only nodes along the mo ...

Posted on Tue, 21 Jul 2026 16:09:02 +0000 by philipolson

Solution: QOJ-6322 / The 1st Universal Cup. Stage 12: Ōokayama - F. Forestry

Introduction This is a challenging problem that combines segment tree merging with dynamic programming optimization. While it follows a relatively standard template, the overall difficulty level is high. Prerequisites: Dynamic programming, tree-based DP, segmant tree with dynamic node allocation, segment tree merging. Problem link: Click here D ...

Posted on Fri, 10 Jul 2026 16:49:46 +0000 by Masna