Efficient Algorithms for GCD Pair Counting, Incremental Construction, and Circular Coloring
Counting GCD Pairs in Dynamic Multisets
Maintain a multiset of positive integers with insertion and deletion operations. For each query, count unordered pairs (i, j) where i ≠ j and gcd(i, j) = k.
Constraints: n, V ≤ 10^5.
Conisder the change in answer count:
$$\sum_{i=1}^{V}c_i[\gcd(i,x)=k]$$
Let x' = x/k:
$$\sum_{i=1}^{\lfloor V/k \rfloor}c_{ ...
Posted on Sat, 06 Jun 2026 17:32:00 +0000 by dhruvasagar
Backtracking Algorithms for Combination Sum and Palindrome Partitioning
Combination Sum
The objective is to find all unique combinations from a list of candidate numbers that sum up to a given target. Each number may be used multiple times.
The solution uses recursive backtracking with the following approach:
Parameters include the candidate array, target value, current combination, and results collection
Terminat ...
Posted on Fri, 05 Jun 2026 17:01:53 +0000 by abushahin
SMU Summer 2024 Contest Round 4 - Problem Editorials
Made Up
Problem Statement Given three sequences A, B, C, count the number of pairs (i, j) such that A[i] = B[C[j]].
Solution Approach Since all values are bounded between 1 and N, we can use frequency counting. For each value v, count how many times it appears in array A (stored in cntA) and how many times it appears as B[C[j]] (stored in cntB) ...
Posted on Thu, 04 Jun 2026 16:57:11 +0000 by reyes99
Backtracking Algorithms: A Comprehensive Introduction
Core Concept
Backtracking is a systematic search technique that explores all possible solutions by building candidates incrementally and abandoning ("backtracking") a candidate as soon as it determines that the candidate cannot possibly lead to a valid solution.
Problems Addressed
Backtracking effectively solves the following categori ...
Posted on Sat, 30 May 2026 20:01:14 +0000 by kuri7548
Counting Unlabeled Colored Trees With Maximum Independent Set Size Constraints
The problem requires counting unlabeled unrooted colored trees with maximum independent set size falling in a given range, which is an extended variant of classic unlabeled unrooted tree counting, so we can adapt standard techniques for that problem.
For unlabeled rooted trees, the generating function $F$ satisfies $F = x\mathcal{E}(F)$, where ...
Posted on Tue, 26 May 2026 19:13:22 +0000 by isurgeon
Competitive Programming Contest Solutions: Segment Trees and Combinatorial Optimization
Problem 1: Maximum Goals and Assists
Problem Overview
Given two arrays representing goals and assists for multiple players, process queries that ask for the maximum total balls needed under different matching scenarios.
Key Observations
The problem essentially asks for the maximum value among three distinct scenarios:
Scenario 1: Each assist ca ...
Posted on Sun, 24 May 2026 16:31:07 +0000 by KingIsulgard
AtCoder ABC 069 Solutions
Problem A - 4
Question
With (n) horizontal lines and (m) vertical lines drawn on a plane, how many axis-aligned rectangles are formed that contain no interior lines?
Solution
Consider each dimension independent.
Along any straight line, (n) distinct points partition the line into (n - 1) segments. These segments serve as the edges of our rectan ...
Posted on Fri, 22 May 2026 20:05:22 +0000 by suresh1
Introduction to Digit Dynamic Programming
When solving counting problems over large numerical ranges, traditional anumeration becomes inefficient due to redundant computations. Consider counting processes from 7000 to 7999, 8000 to 8999, and 9000 to 9999. These intervals share a common pattern: the lower three digits cycle from 000 to 999, with only the thousand's digit varying. This o ...
Posted on Wed, 20 May 2026 18:55:12 +0000 by cbrooks
Dynamic Programming on Increasing and Decreasing Sequences
Consider a sequence $A = (a_1, a_2, \dots, a_n)$. We want to partition $A$ into contiguous subsequences, and then arrange these subsequences to form a new sequence $f_1, f_2, \dots, f_k$. Each contiguous subsequence $f_1, \dots, f_p$ must satisfy either $f_1 \le f_2 \le \dots \le f_p$ or $f_1 \ge f_2 \ge \dots \ge f_p$. The cost associated with ...
Posted on Tue, 19 May 2026 12:41:33 +0000 by thedream
Computing Total Weight Contributions and Sequence Constraints via Combinatorics and Matrix Exponentiation
Problem D: Weighted Permutation Sum
Given a sequence of numbers, consider generating all its non-empty subsequences, constructing a permutation by repeatedly removing the last element until one remains, and summing the final remaining numbers across all such processes. The problem requires computing the total sum over all subsequences.
For anal ...
Posted on Mon, 18 May 2026 21:36:44 +0000 by fredmeyer