NOI Online 2022 Contest Solutions: Monotone Stacks, Set Systems, and Multidimensional Partial Orders

Problem 1: Stack Elimination with Color Constraints Given a sequence where each element possesses a color and value, process multiple queries. For each query $[L, R]$, simulate a monotonic stack traversal from left to right: pop the top while it is less than or equal to the current value or shares the same color. Determine how many positions wi ...

Posted on Tue, 22 Sep 2026 16:39:41 +0000 by ldb358

Graph Theory and Union-Find Data Structure Applications in Island Problems

Maximum Island Area Problem Given a matrix of 1's (land) and 0's (water), calculate the maximum island area. Islands consist of adjacent land cells connected horizontally or vertically. Input: 4 5 1 1 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 1 1 Output: 4 The solution uses DFS or BFS to traverse each island component and count its area. Python Impleme ...

Posted on Sat, 19 Sep 2026 16:43:05 +0000 by nitram

Cloud Service Billing System Implementation

Cloud Service Billing Calculation Develop a program to calculate customer bills for a cloud service based on usage logs and pricing factors. The input consists of billing logs and a list of billing factors with thier unit prices. Each billing log entry contains timestamp, customer ID, billing factor, and usage duration. If multiple log entries ...

Posted on Wed, 16 Sep 2026 16:46:03 +0000 by yakoup46

Minimum Operations to Make Array Equal and Valid Swap Sequence Analysis

Problem A: Array Equalization Strategy The optimal approach involves transforming all elements to match the most freqeunt value in the array. Initial attempts with incorrect assumptions led to multiple failed submissions. #include <iostream> #include <vector> #include <algorithm> using namespace std; void solve() { int t ...

Posted on Fri, 11 Sep 2026 16:36:37 +0000 by 156418

Techniques for Solving Problems Based on Partial Order Relations

Many computational problems require determining answers based on partial order relationships between elements. When only the relative ordering matters, we can employ specialized enumeration strategies to sidestep complex case-by-case analysis. The main approaches include: Comparison Operators (): Process elements sequentially from smallest to ...

Posted on Sat, 05 Sep 2026 16:26:53 +0000 by OldWolf

Solving Array Grouping with Prime Factors and Union-Find

Problem Analysis The task is to partition an array of integers into two groups. The core requirement is that within each group, any two numbers must share at least one common prime facter. If all numbers are interconnected (i.e., they form a single group), then it's impossible to create two valid groups, and the solution should indicate this. O ...

Posted on Sat, 05 Sep 2026 16:20:27 +0000 by webren

AtCoder Beginner Contest 049 Solutions

Problem A Determine if a given character is one of the vowels a, e, i, o, u. A simple approach uses a hash map to store the vowels. For efficiency, characters are hashed by subtracting 'a', and a custom hash table implementation handles lookups. template <class T, int P = 314159> struct hashmap { u64 id[P]; T val[P]; int rec[P ...

Posted on Mon, 24 Aug 2026 16:13:46 +0000 by noobh

Maximizing Sum of Minimum Edge Weights on Tree Paths

Given a tree with n nodes (≤ 10⁶) and weighted edges, define Min(x, y) as the minimum edge weight along the unique path between nodes x and y. The goal is to compute: max_{r=1}^n Σ_{v ≠ r} Min(r, v) A naive approach would compute the sum for each root r by traversing all paths, yielding O(n²) complexity — infeasible for large n. Instead, revers ...

Posted on Sun, 16 Aug 2026 16:36:12 +0000 by Dasndan

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

Solving Math and Graph Problems from a Competitive Programming Contest

Problem 1: Counting Valid Pairs with LCM Condition Problem Description Given an integer n where 1 ≤ n ≤ 10^8, determine the number of pairs (x, y) such that 1 ≤ x, y ≤ n and the following inequality holds: lcm(x, y) / gcd(x, y) ≤ 3 Note that lcm(x, y) = (x * y) / gcd(x, y)^2. Solution Approach This is a straightforward number theory problem. L ...

Posted on Mon, 10 Aug 2026 16:39:42 +0000 by HaVoC