CCPC Qinhuangdao Contest: Problem Solutions and Code

Problem A. Is Your School the Kingdom of Construction I Approach The official solution provides a clear construction method. We need to generate exactly k coordinate pairs (x, y) where both coordinates are between 1 and n. First, we construct a base set of edges forming a connected structure. Then, if additional pairs are needed, we fill in the ...

Posted on Sun, 10 May 2026 20:13:05 +0000 by ragefu

Minimizing Interval Length Difference for Common Intersection Using Segment Trees

Given $n$ closed intervals on a number line, the objective is to select exactly $m$ intervals such that they share at least one common coordinate point. The cost of a selection is defined as the difference between the maximum length and the minimum length among the chosen intervals. The length of an interval $[l, r]$ is calculated as $r - l$. T ...

Posted on Fri, 08 May 2026 22:58:06 +0000 by Jak-S

Segment Tree Template for Competitive Programming: Point Updates and Range Queries

The following reusable segment tree implementation uses 0-based indexing with half-open intervals [l, r). It supports point assignment, point addition, range queries, and methods to locate the first or last endex satisfying a custom predicate. #include <bits/stdc++.h> template<typename Info> struct SegmentTree { int size = 0; ...

Posted on Thu, 07 May 2026 09:24:23 +0000 by ainoy31