Monotonic Stack Techniques for Maximum Subrectangle Problems

Monotonic Stack Fundamentals Monotonic stacks enable linear preprocessing to find: Prefix/suffix maximum/minimum positions in sequences Next greater/smaller element positions for each index Problem B3666: Suffix Maximum Positions Given a dynamically growing array, after each insertion, find all suffix maximum indices and output their XOR sum. ...

Posted on Sun, 05 Jul 2026 17:15:02 +0000 by Hayce

Selected Solutions from 2024 Nowcoder Winter Algorithm Camp

A. Cosmic End Find a number within a given range that is the product of three distinct primes. Given the small constraitn (upper bound ≤ 100), precompute small primes and check all combinations of three distinct ones. The maximum third prime needed is around 100/(2×3) ≈ 16, so checking primes up to 19 suffices. #include <bits/stdc++.h> us ...

Posted on Sun, 05 Jul 2026 16:45:51 +0000 by heimskr

Algorithmic Analysis and Implementations for Contest 883 Division 3

Problem A: Rope Cutting Condition The task requires determining how many ropes must be severed based on their attachment points. Each rope connects a nail at height a to a branch at height b. A cut is mandatory whenever the nail is positioned strictly higher than the branch. The algorithm iterates through all given pairs, evaluates this inequal ...

Posted on Sat, 04 Jul 2026 17:59:37 +0000 by nmohamm

Solutions for AtCoder Beginner Contest 052 Problems in C++

A – Two Rectangles [Max Area Logic] Given the dimensions of two rectangles: Rectangle 1: (A \times B) Rectangle 2: (C \times D) Determine and output the larger area. Tie-breaking is irrelevant. i64 a, b, c, d; std::cin >> a >> b >> c >> d; i64 r1 = a * b, r2 = c * d; i64 best = (r1 >= r2) ? r1 : r2; std::cout <&l ...

Posted on Sun, 28 Jun 2026 17:59:34 +0000 by Angus

Efficient Submatrix Sum Queries Using Prefix Sums

Problem Statement Given an n×m integer matrix and q queries, each query specifies the coordinates of the top-left and bottom-right corners of a submatrix. For each query, compute the sum of all elements within the specified submatrix. Solution Approach The problem can be efficiently solved using 2D prefix sums. By precomputing the cumulative su ...

Posted on Sun, 28 Jun 2026 17:36:37 +0000 by trufla

Segment Tree Variants and Categorization Techniques

Linear Operation Segment Trees The most basic form of segment tree handles linear operations that satisfy commutativity and associativity, such as addition. Since operations do not depend on each other, maintaining lazy propagation is straightforward. For single-point modifications, a Fenwick Tree (Binary Indexed Tree) is often a more efficient ...

Posted on Sun, 28 Jun 2026 16:55:59 +0000 by sycoj0ker

Technical Analysis of Xiangtan University Spring 2023 Freshman Programming Contest

Problem A: Strategic Allocation This challenge involves selecting a subset of items to meet a weight capacity requirement with the minimum count. The optimal approach utilizes a greedy strategy. By prioritizing larger weights first, we minimize the number of items required to reach the target threshold. void processAllocation() { int itemCo ...

Posted on Sat, 27 Jun 2026 16:02:21 +0000 by mattpointblank

Solutions for AtCoder Beginner Contest 314 Programming Challenges

Display the first N+2 digits of π (including the decimal point). #include <iostream> #include <string> const std::string PI_DIGITS = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679"; int main() { int digits; std::cin >> digits; std::cout << P ...

Posted on Thu, 25 Jun 2026 17:42:23 +0000 by kjtocool

Efficient Range Queries and Updates: Prefix Sums and Difference Arrays

1. Prefix Sum Technique 1.1 One-Dimensional Prefix Sum The prefix sum algorithm is an optimization technique used to calculate the sum of elements within a specific range $[L, R]$ in $O(1)$ time after an $O(N)$ preprocessing step. In a naive approach, calculating range sums repeatedly would result in $O(N \times M)$ complexity for $M$ queries; ...

Posted on Sun, 21 Jun 2026 17:52:00 +0000 by musicbase

Programming Competition Problem Solutions and Analysis

Mathematical Caclulation Problem Given the formula for distance between a point and a line, we can simpliyf the calculation to |x-y| * 50: #include <iostream> #include <cmath> int main() { int x, y; std::cin >> x >> y; std::cout << abs(y - x) * 50 << '\n'; return 0; } String Output Problem S ...

Posted on Fri, 19 Jun 2026 18:14:18 +0000 by jantheman