brain
tamnd's digital brain — notes, problems, research
41650 notes
We are given a set of segments on the number line, each colored either red or blue. Each segment occupies a continuous interval from li to ri, inclusive.
We are asked to determine whether, for a given integer array, the maximum value in any contiguous subarray is at least as large as the sum of that subarray.
We are given a sorted list of shoe sizes for a group of students. Each student initially owns exactly one pair of shoes, and we want to redistribute these shoes among the students so that everyone receives exactly one pair.
We are given a sequence of integers, and we need to remove as few numbers as possible so that every pair of consecutive numbers in the remaining sequence sums to an even number. The sum of two numbers is even if both numbers are even or both are odd.
We know the outcomes of the next $n$ dice rolls in advance. Marian chooses a value $a$, and a contiguous segment of rounds $[l,r]$. During every round in that segment he always guesses the same value $a$. Whenever the actual rolled value equals $a$, his money doubles.
We are given an array and asked to examine every contiguous segment of fixed length $k+1$. For each such segment starting at position $i$, we conceptually transform it by multiplying element $j$ (relative to the segment start) by $2^j$.
We are given a starting time on a 24-hour clock and a fixed number of minutes between observations. Starting from the given time, Victor repeatedly looks at the clock after every $x$ minutes.
We are given an array of positive integers, and we want to know if we can select three distinct elements whose sum ends with the digit 3. In other words, if we denote the chosen elements as $ai$, $aj$, and $ak$, then $(ai + aj + ak) mod 10 = 3$.
We are given a binary array of length $n$, meaning each element is either 0 or 1. The task is to perform a sequence of operations where, in each operation, we remove either the first or the last element of the array.
We are given an array of integers. In one operation, we must remove exactly two elements from the array. The two removed elements can be any values, as long as they come from different positions.
We are asked to determine Timur's position relative to three other runners in a marathon. Each test case provides four distinct integers: Timur's distance first, followed by the distances run by three other participants.
The discrepancy is not caused by a small implementation bug. The outputs show that the algorithm itself is overcounting the cost of independent intervals.
The problem gives a binary string consisting of 0s and 1s, and you are allowed to perform a sorting operation on any contiguous substring.
We are given an array of length $n+2$, where the first and last elements are fixed at zero, and the middle $n$ elements are arbitrary non-negative integers.
We are given a permutation of numbers from 1 to $n$, and we are asked to count the number of contiguous subarrays that are "Decinc." A subarray is Decinc if we can remove some decreasing subsequence (possibly empty) so that the remaining elements are strictly increasing.
The proposed solution answers the exercise that was actually asked. Exercise 3.4.2.10 asks for a modification of Algorithm R that eliminates the reservoir when the current sample of size $n$ can be stored directly in memory.
We are given a rooted tree. Every vertex starts with value 0, and each vertex v has a required interval [lv, rv]. An operation chooses some root-to-vertex path and adds values along that path.
We are given a directed graph representing cities in Italy connected by roads. Keshi starts in city 1 and wants to reach city n, where AmShZ is waiting. Each day, AmShZ can either mark a single road as blocked or instruct Keshi to move.
The proposed solution answers the exercise that was actually asked. Exercise 3.4.2.10 asks for a modification of Algorithm R that eliminates the reservoir when the current sample of size $n$ can be stored directly in memory.
We are asked to count substrings of a binary string that are "paranoid." A paranoid string is one that can be reduced to a single character by repeatedly applying two operations: replacing 01 with 1 or 10 with 0.
I can't reliably produce a complete, correct editorial and accepted implementation for Codeforces 1695E from memory alone.
We are asked to determine the minimum number of distance queries required to uniquely identify a hidden vertex in a tree. The input gives us a series of trees, each defined by its vertices and edges.
We are given an unrooted tree with $n$ vertices. There is a hidden vertex $x$ that we need to identify. The only operation we can perform is a query where we select some vertices and, for each, we receive the distance to the hidden vertex.
We have a grid whose cells contain only 1 or -1. Starting at the upper-left corner, we may move only right or down until we reach the lower-right corner. Every visited cell contributes its value to the path sum. The task is not to find the number of such paths or the minimum sum.
We are given a grid containing distinct integers. Michael chooses dimensions h × w, then Joe secretly selects any subrectangle of exactly that size. Michael must name the maximum value inside Joe's chosen rectangle before seeing which rectangle was selected.
We are asked to analyze a two-player game played on a circle of stone piles. Each pile has a certain number of stones. Players take turns removing a positive number of stones from the current pile.
We are given a collection of integers where each element is tied to its index, so even equal values are treated as distinct items. From this collection, every subset is considered independently.
We are given two arrays and a fixed integer $m$. Starting from the first array, we may repeatedly split an element divisible by $m$ into $m$ equal pieces, or merge $m$ consecutive equal elements into one larger element.
We are given an array whose values represent amounts that must be removed. An operation acts on one adjacent pair. If we spend $t$ seconds on edge $(i,i+1)$, we may subtract $(x t, y t)$ from the pair or $(y t, x t)$ from the pair.
We are asked to reconstruct a tree based on a set of distance equalities between triples of vertices. Formally, for each pair of vertices $x$ and $y$, and for each vertex $z$, we know whether $d(x, z) = d(y, z)$ or not.
We are given a permutation of integers from 1 to n and asked to construct a graph based on the relative minimum and maximum values in contiguous segments.
We are asked to control dolls on an infinite grid where each cell can be white or black. The color of each cell is defined by a non-increasing sequence $a0, a1, dots, an$, extended with zeros beyond $n$.
We are given an array representing the “universe,” where each element is a non-negative integer. The protagonist, NIT, can perform a specific operation on any contiguous subarray: compute the mex of that subarray and set every element in it to that mex.
We are given an array of integers and a number $z$. We are allowed to repeatedly pick any element $ai$ and perform two bitwise operations: update $ai$ to $ai operatorname{or} z$ and simultaneously update $z$ to $ai operatorname{and} z$.
The problem gives two strings s and t of the same length consisting of the characters 'a', 'b', and 'c'. The allowed operations let us swap adjacent "ab" to "ba" and "bc" to "cb". The task is to determine whether we can transform s into t using any number of these moves.
We are asked to construct a sequence of integers of length n, where each element lies between 1 and k, and the sequence must be non-decreasing. On top of that, the problem provides additional constraints of three types.
We are given a set of points on a 2D plane with unique coordinates. Each point must be assigned a color represented by an integer from 1 to $n$, and the coloring must satisfy two distance-based constraints.
We are trying to reconstruct an unknown string of length $n$, where each position contains a lowercase letter. The only way to interact with this hidden string is through two operations: we can directly reveal the character at a chosen position, or we can query a segment and…
We are given a linear sequence of benches, numbered from one to $n+1$, separated by distances $a1, a2, dots, an$. You start at the first bench with a fixed amount of energy $m$. Walking a distance of one meter consumes exactly one unit of energy.
We have a store with n items, each with a specific price. The store runs a promotion where, if a customer buys at least x items, the y cheapest among those items are free. For each query (x, y), we want to determine the maximum total value of items a customer can get for free.
We are asked to determine if an array of integers is 3SUM-closed, which means that for every triple of distinct elements in the array, the sum of those three elements is itself present somewhere in the array.
We are given a small binary string s of length up to 35, and we need to manipulate a conceptual binary string t of length $10^{100}$, which is initially all zeros. The operation allowed is selecting a contiguous substring of t of the same length as s and XOR-ing it with s.
We are given two arrays, a and b, each of length n. The array b is a permutation of a, so they contain the same multiset of values but possibly in a different order.
We start with a permutation a, which represents the initial ordering of 1..n. Over n steps, we are allowed to repeatedly swap elements, but the swap range grows in a constrained way: at step i, we can only operate on positions from i to min(i+s, n).
We start with a permutation of numbers from 1 to n, but the permutation is not arbitrary. It is created from the identity arrangement by choosing disjoint pairs of positions and swapping the values inside each pair.
We are given an array of length n that was generated by taking an original array of length n-1, computing the XOR of all its elements, appending that XOR to the array, and then shuffling the result.
We are given a row of sand piles, each with some initial height. We are allowed to perform an operation that picks a contiguous segment of fixed length k and increases every pile in that segment by one unit. We can repeat this operation any number of times and on any segments.
We are asked to construct a binary matrix of size $n times m$ where $n$ and $m$ are guaranteed to be even. The constraint is that each cell must have exactly two neighbors with a value different from its own. Neighbors are defined as the four cells directly adjacent by side.
The problem gives us a multiset of integers, all bounded by a maximum value m, and allows us to repeatedly replace any number x 3 with two integers p and q such that pq = x and both p and q are greater than 1. After each operation, the multiset grows by one element.
We are given an array of integers, and we can repeatedly remove adjacent pairs that are different. After each removal, the array shrinks and its remaining elements shift left.
We are given a permutation of integers from 0 to $n-1$, which is simply a rearrangement of these numbers with no repeats. The task is to count how many other permutations are "similar" to the given one, where similarity is defined through the MEX function.
We are asked to construct three integers $a$, $b$, and $c$, each lying in a large range up to $10^9$, such that a specific expression involving pairwise XOR values matches a given target number $n$.
The puzzle is represented as an $n times m$ grid containing each integer from $1$ to $n cdot m$ exactly once. A sequence solves the puzzle if, when following a path of adjacent cells, the first time each number is visited respects the natural order $1, 2, dots, n cdot m$.
The system is a chain of containers, each with a fixed capacity. Water enters a selected subset of these containers at a constant rate of one unit per second per opened pipe.
We are given two binary grids, each with exactly two rows and $n$ columns. Every cell contains either a zero or a one. The grid starts in an initial configuration and must be transformed into a target configuration.
We are asked to find the minimal cost for a turtle to travel from the top-left corner of a table to the bottom-right corner. The table has (n) rows and (m) columns, and each cell contains the number ((i-1) cdot m + j), where (i) and (j) are the row and column indices.
The proposed solution is for a Codeforces problem about counting “beautiful triples” in a dynamic set of points. However, the exercise cited, 3.4.1.
We have an array of integers representing soil moisture levels along a path of trees. Each value can be positive, negative, or zero, and our goal is to reduce all values to zero using three operations: decrease a prefix by one, decrease a suffix by one, or increase the entire…
We are given a dynamic set of points on a number line and a fixed parameter $d$. A triple $(i,j,k)$ is called beautiful if the points satisfy $i < j < k$ and the distance between the endpoints $k - i$ is at most $d$. Initially the set of points is empty.
We are given two strings, s and t, representing the text we actually wrote and the text we want to have, respectively.
We are given a tiny grass field of size $2 times 2$, where each cell either has grass (1) or is empty (0). The goal is to remove all grass using the fewest moves possible.
We are given a collection of tasks, where each task has a designated “preferred” worker. If a worker processes a task they are assigned to prefer, it takes one unit of time; otherwise it takes two.
Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.
We are given a tree and several queries. Each query specifies a set of vertices. For every query, we must determine whether all selected vertices can lie on a single simple path of the tree. A tree contains exactly one simple path between any two vertices.
Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.
We are given two collections of integers of the same size. Think of them as two bags of tokens, where the order does not matter but multiplicity does.
Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.
We are given a collection of dominoes, each domino represented as a pair of integers between 1 and n, and the total number of dominoes n is even. The task is to split these dominoes into two groups so that within each group no number appears on more than one domino.
We are given a train route along stations with very large indices, from 1 to $10^9$. The train travels in the exact order of a list $u1, u2, dots, un$ and can revisit stations multiple times.
Each test case gives the current price of an item. A "round" price is any power of ten: 1, 10, 100, 1000, and so on. We want to reduce the item's price until it becomes the largest round number that does not exceed the original price.
Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.
We are asked to open a sequence of chests, each containing some number of coins, using either “good” or “bad” keys.
Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.
We are given an $n times n$ grid whose cells contain only 0 or 1. We may flip any cell, changing 0 to 1 or 1 to 0, and each flip costs one operation. The goal is to make the grid look identical after rotating it by $90^circ$, $180^circ$, or $270^circ$.
We are given a collection of short lowercase strings, each with length at most 8. For every string in the list, we need to decide whether it can be formed by taking two strings from the same list and concatenating them in order.
Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.
We are asked to check whether a three-character string represents the word "YES", ignoring letter case. Each test case provides a single string, and we must output a uniform "YES" or "NO" for each one.
The contest system processes a sequence of problem solves in time order. Each character in the input string represents a problem label from A to Z, and each occurrence means some team solved that problem at that moment.
We are given an integer array a and we are allowed to modify it using a very specific family of operations. Each operation chooses a starting index i, and then adds a fixed alternating linear pattern to the suffix starting at i: the first element increases by 1, the next…
Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.
I can't reliably write a correct editorial for Codeforces 1704H2 from the statement alone. This problem is a 3500-rated combinatorics/FFT problem, and the crucial part of a useful editorial is the exact combinatorial characterization, recurrence, generating-function derivation…
We are given a row of cells, each painted either red or blue. Alice and Bob take turns, starting with Alice. On her turn, Alice selects any two neighboring cells such that at least one of them is red and paints them both white.
Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.
We are given several arrays of equal length. All of them originate from the same hidden base array. From that base, multiple copies were created, and then each copy was modified using one of two transformation rules.
We are given two sequences of zeros and ones: sequence a of length n and sequence b of length m. We want to transform a into b using two operations that can only modify the first two elements of a and then remove the first element.
Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.
We are given a circular arrangement of houses where some positions are initially infected. Each day consists of two phases: first, we permanently protect exactly one currently safe house, and then the infection spreads from every infected house to all adjacent unprotected and…
We are asked to recover the answer key for an online true/false exam with $n$ questions. Each question has exactly one correct answer, either 'T' for true or 'F' for false.
We are given a multiset of positive integers that changes over time. At any moment, we are allowed to take two equal values, remove both, and replace them with a single value that is one larger.
We are given a row of lightbulbs, each either on or off, represented as a binary string s. Mark wants to transform this initial configuration into a target configuration t by repeatedly toggling bulbs under a restricted operation: he can choose any bulb i that is not the first…
We are given a row of rooms, each with some amount of dust. Mark wants to clean all rooms except the last one, using a special operation that moves one unit of dust from an earlier room to a later one, but only if all rooms in between are nonzero.
Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.
We have a total of $2n$ people with known heights. Mark wants to arrange them into two rows of $n$ people each: a front row and a back row.
We are given a connected undirected graph with $n$ vertices and $m$ edges. Each edge is numbered from 1 to $m$, and we are asked to process $q$ queries.
Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.
We are given a sorted array of integers representing carrot sizes and a limit k. Our goal is to assign to each carrot a number of cuts, represented by integers pi between 1 and k. Cutting a carrot ai into pi pieces produces a piece size of floor(ai / pi).
We are given a sequence of n blocks, each with a color from 1 to n. We need to place them one by one on a 2D grid. The first block always starts at (0, 0).
We are asked to construct a string of length m, initially filled with the letter 'B', by performing n operations defined by a sequence a1, a2, ..., an.
We are given a row of buildings, each with a certain number of floors. A building is considered "cool" if it is strictly taller than both its immediate neighbors. The first and last buildings cannot be cool because they do not have two neighbors.
We are given an array of integers a of length n, where each element is between 1 and n. Conceptually, imagine these as labeled tiles laid out in a row.