title-img


Inverse RMQ

Range Minimum Query is a well-known problem: given an array of distinct integers with size n=2^k and m queries, find the minimum element on subsegment [Li,Ri]. One of the most efficient and famous solutions to this problem is a segment tree. A segment tree is a full binary tree with 2.n-1 nodes where the leaves contain the values of the original array and each non-leaf node contains the minimum value of its entire subtree. Usually, a segment tree is represented as an array of integers with

View Solution →

Two Subarrays

Consider an array, A = a0,a1,...,an-1, of n integers. We define the following terms: Subsequence A subsequence of A is an array that's derived by removing zero or more elements from A without changing the order of the remaining elements. Note that a subsequence may have zero elements, and this is called the empty subsequence. Strictly Increasing Subsequence A non-empty subsequence is strictly increasing if every element of the subsequence is larger than the previous element. Subarray

View Solution →

Lovely Triplets

Daniel loves graphs. He thinks a graph is special if it has the following properties: It is undirected. The length of each edge is 1. It includes exactly P different lovely triplets. A triplet is a set of 3 different nodes. A triplet is lovely if the minimum distance between each pair of nodes in the triplet is exactly Q. Two triplets are different if 1 or more of their component nodes are different. Given P and Q, help Daniel draw a special graph. Input Format A single line conta

View Solution →

Array Construction

Professor GukiZ has hobby — constructing different arrays. His best student, Nenad, gave him the following task that he just can't manage to solve: Construct an n-element array, A, where the sum of all elements is equal to s and the sum of absolute differences between each pair of elements is equal to k. All elements in A must be non-negative integers. A0+A1+...+An-1 = s ΣΣ |Ai-Aj| = k If there is more then one such array, you need to find the lexicographically smallest one. In the cas

View Solution →

Self-Driving Bus

Treeland is a country with n cities and n - 1 roads. There is exactly one path between any two cities. The ruler of Treeland wants to implement a self-driving bus system and asks tree-loving Alex to plan the bus routes. Alex decides that each route must contain a subset of connected cities; a subset of cities is connected if the following two conditions are true: There is a path between every pair of cities which belongs to the subset. Every city in the path must belong to the subset.

View Solution →