brain
tamnd's digital brain — notes, problems, research
43815 notes
We are dealing with a complete rooted binary tree, meaning every non-leaf node has exactly two children. Each leaf has a “hunger value” representing the number of cookies it must ultimately receive. Non-leaf nodes have a selector that decides which child a cookie moves to.
We are given an array where each position points to a value in the same range as indices. You are allowed to repeatedly pick an index i and swap the value stored at position i with the value stored at position a[i].
We are given an array of integers and a strange operation that repeatedly reduces the array by splitting it into two non-empty parts, computing the XOR of each part, and discarding the part with the smaller XOR value.
We are given a set of quests, each of which can only be completed at a specific hour within a repeating game day. Some quests depend on others, meaning they cannot be completed until certain prior quests are done.
We are given an $n times m$ board partially covered with dominoes. Each domino occupies exactly two adjacent cells, either horizontally or vertically. Some cells may remain empty.
We are given an array of distinct integers ranging from 0 up to n, inclusive. The task is to repeatedly update the array in a very specific way: for each element from left to right, replace it with the MEX (minimum excluded value) of the current array.
A channel has n subscribers. When a new post is published, exactly a subscribers are online, so those a people immediately read the post. After that, we receive a sequence of notifications. A '+' means some subscriber came online, and a '-' means some subscriber went offline.
We are given a permutation of numbers from 1 to n, and we want to transform it into the identity permutation where each value sits in its matching index position.
Let the grid cells be vertices of an $n times n$ grid graph. A final placement of the numbers $1 ldots n^2$ is valid if every vertex except the one containing $1$ has at least one adjacent vertex with a smaller number.
We start with two square boards of size $n times n$, each containing the numbers $1$ to $n^2$ exactly once. Think of each number as a labeled tile. The initial board is some arrangement of these tiles, and we want to transform it into a target arrangement.
We are asked to compute the expected number of moves to reach or exceed a target integer n starting from x = 1 when in each move you either increment x by 1 or double it, each with probability 1/2.
We are given an array of integers a of length n. For each query (l, r), we need to zero out every number in a that lies within the range [l, r] using a set of subtraction operations.
We are given a multiset of integers, and we repeatedly imagine picking two positions independently, forming an ordered pair of values $(a, b)$. Along with $a$ and $b$, both players also learn the bitwise OR $x = a mid b$.
The failure here is not algorithmic at all. The expected logic is correct: the answer is the minimum absolute value in the array. The issue is purely an implementation bug that leads to no output being printed.
We are given a square grid filled with bits, and the goal is to turn every cell into zero. The only allowed move flips values in a very specific geometric pattern: you pick a cell as a “center”, and it toggles itself and all cells strictly below it that lie within a…
The problem gives us three integers: a starting value x, an ending value y, and a length n. We need to build an array a of length n that starts at x and ends at y, is strictly increasing, and has strictly decreasing consecutive differences.
We are given a string and two kinds of moves that let us rearrange its characters in a constrained way. One move swaps characters that are two positions apart, and the other reverses a contiguous block of fixed length $k$.
We are asked to compute the expected number of moves to build a tower of height N using identical small rocks, where each placement may trigger a cascading fall of the top rocks. Every time a rock is placed at height x, the topmost rock has a probability Px/100 of falling.
We are given a weighted tree, so there is exactly one simple path between any two vertices and every edge contributes a distance equal to its weight. The diameter of this tree is the maximum distance between any pair of vertices under these edge weights.
We start with a single stack of $N$ jackets. Each jacket has a color, and the order is fixed from top to bottom. There is a second empty stack.
Each carriage initially contains some number of passengers. A passenger starting in carriage i may move left or right, but cannot cross more than Di doors.
We are given a grid with $N$ rows and $M$ columns. A game piece starts at the top-left cell $(1,1)$. From any cell, the piece can move either to the right within the same row or downward within the same column, but never left or up.
We are given a collection of $N$ sets, each set is formed from integers in the range $1$ to $K$. The sets are unordered internally, but the array of sets is ordered. After we construct these $N$ sets, we are allowed to permute them in any order.
We are maintaining a group of players, each described by two evolving attributes: an offensive value and a defensive value. Over time, both attributes can change independently through updates.
We are managing three elevators inside a tall building. Each elevator sits on a floor and can move up or down, paying a cost proportional to how far it travels.
We are given a list of integers, and we can modify any element by repeatedly incrementing or decrementing it by one. Each such unit change costs one operation.
We are given several rows of numbers, each row representing a sequence of rewards spread across time positions from 1 to M. We will perform exactly M − K + 1 actions, and each action is tied to a sliding window of K consecutive positions that moves from left to right.
We are given a directed acyclic graph where each vertex has an ordered list of outgoing edges. Each edge carries a label, either 0 or 1, and points to another vertex.
We are given two integers, but instead of being written in decimal form, they are described by their prime factorizations. One number, call it $X$, is fully determined by a list of primes and their exponents. The other number $Y$ is described the same way.
We are given an array of hidden integers and a fixed segment length $k$. We are not allowed to directly inspect the array, but we can ask queries on any contiguous block of exactly $k$ elements.
We start with a rooted tree $G$ on $n$ vertices, rooted at vertex $1$. For every vertex $v$, we look at the “subtree of $v$” defined as all vertices whose path from the root passes through $v$.
We are given a binary string and we are allowed to “modify” it using another binary string of the same length. That second string is not arbitrary in its effect, because it is constrained only by how many ones it contains.
We start with an array a of length n filled with zeros, and we want to transform it into a target array b of the same length.
We are given a hidden array of length $n$, where each element is an integer. We do not see the array directly. Instead, we are allowed to ask queries on contiguous segments of fixed length $k$.
We are given a sorted set of distinct integers. We do not control this set directly; instead, we interact with an opponent through moves that change it. Each move we either insert a new number into the set or allow Bob to remove a number under a restriction.
We are given an array a of length n. We must construct a permutation b of numbers from 1 to n such that when we subtract element by element, forming ci = ai - bi, the number of distinct values appearing in c is as large as possible.
We are given an array of integers. In one move, we are forced to pick a segment whose sum is as large as possible among all subarrays of the current array, and decrease every element in that segment by one.
The mismatch is not coming from MEX computation anymore. The segment MEX logic in the previous version is actually fine for this problem scale.
We are given an integer array, and we are allowed to split it into several contiguous blocks. Each block has a sum, and we call these block sums a new array. The constraint is not on individual blocks but on every contiguous group of blocks.
We are given only the degree of each vertex in a graph that is known to be a pseudotree. That means the final graph must be connected and contain exactly one cycle, while having exactly $n$ edges on $n$ vertices.
We are given an array of integers representing how many candies each person initially holds. The process that follows is a sequence of transfers, where each person will act exactly once as a giver and will choose a single recipient.
We are asked to construct an $n times m$ matrix where every row is a permutation of ${0, 1, dots, m-1}$. This already forces a strong structure: each row contains each value exactly once, so the matrix is composed of $n$ rearrangements of the same multiset.
We are given a group of people at a party, each initially holding some number of candies. Each person can give a certain number of candies to another person exactly once, with the amount being a power of two and not exceeding the candies they currently hold.
We are given several test cases, each describing a complete weighted travel system on a plane. Every city is a point with integer coordinates, and we are allowed to fly directly between any pair of cities.
We are working with a weighted directed graph with n vertices and m edges. Each vertex can be “highlighted” or “normal,” starting with all vertices normal.
We are given an array of integers, and we are allowed to carve it into several disjoint contiguous segments, leaving some elements unused if we want. For every chosen segment we compute its MEX, which is the smallest non-negative integer missing from that segment.
We are given an array, and we look at its prefixes one by one. For each prefix, we treat it as a multiset of integers and imagine repeatedly performing a very unusual operation: we pick any non-empty sub-multiset, remove it, compute its MEX, and insert that MEX back.
We are asked to consider the numbers from 1 to $n$ expressed in base $k$. Once expressed in base $k$, we sort these representations lexicographically, like strings. After sorting, we number the elements from 1 to $n$.
We are given a process that builds an array from left to right using prefix operations. Initially every position is zero.
We are given an array a of length n with integers between 1 and k. From a, we define a square table b of size n × n where each cell (i, j) is the minimum of a[i] and a[j]. Each integer in b represents a "color".
We are given two arrays, a of length n and b of length m. We are allowed to repeatedly choose any element bj from b and update every element of a as ai = ai The key observations from the input constraints are that n and m can each be up to 200,000 but the sum across all test…
We are building an array of length $n$ using non-negative integers, with each element capped at $x$. The array is not arbitrary: it must have a fixed MEX equal to $k$, and among all such valid arrays, we want the one with the largest possible sum of elements.
We are given a sequence of positive integers and we are allowed to perform exactly one transformation: pick a contiguous segment, compress it into a single number equal to the product of all elements in that segment, and replace the segment with that single value.
Let
We are given a set of animals, each with a cost and a "fear" relationship: every animal fears exactly one other animal, and no animal fears itself. When selling an animal, the money earned depends on whether the animal it fears has already been sold.
We are standing at room 1 of a one-dimensional corridor and want to go forward to some room k and then return back to room 1. Time increases by exactly one per step, so reaching room x for the first time takes x−1 seconds, and returning follows the same speed.
We are given a static array of integers, but the array is split dynamically into two groups depending on a binary string. Each position i contributes its value a[i] either to group 0 or group 1 depending on whether s[i] is 0 or 1. The system supports two operations.
We are given a permutation of numbers from 1 to n, and we are allowed to arrange these numbers in any order. Once the arrangement is fixed, we evaluate it using a rule that looks only at certain positions. Two sets of positions matter.
We are given multiple independent queries. Each query provides an interval $[l, r]$, and we need to construct two positive integers $a$ and $b$ such that their sum lies somewhere inside this interval and at the same time $a$ and $b$ share a common divisor greater than one.
We are given two containers holding real-valued amounts of water. One starts with a, the other with b. We also have a cup that can transfer at most c units of water in a single operation.
We are given a string composed only of the letters A and B, and we are allowed to perform two types of operations on adjacent character pairs. In the first operation, an AB pair can be turned into BC to gain a coin. In the second, a BA pair can be turned into CB to gain a coin.
We are asked to determine if one player, Valeriu, can indefinitely avoid being caught by another player, Marcel, in a city modeled as a connected graph with exactly $n$ buildings and $n$ roads. Each building is a node, and each road is an undirected edge connecting two nodes.
We are given a row of trees, each tree carrying two attributes: a height and a number of fruits. We want to choose a contiguous segment of these trees.
We are given a row of coral columns, each with some initial height. We want to build a water tank over this structure by choosing a uniform target height $h$.
We are given a binary string representing a strip of cells, where each position is either black or white. The only operation allowed is choosing any contiguous segment of fixed length $k$ and repainting all cells in that segment to white.
We are given a small collection of digits, and we are allowed to increase exactly one of them by one unit. After this single modification, we compute the product of all digits and want to maximize it.
We are given a $10 times 10$ grid representing a target with five concentric scoring rings. Each cell of the grid either contains an arrow, denoted by X, or is empty, denoted by ..
We are given three distinct cards labeled a, b, and c, arranged in some order. Our goal is to determine whether, using at most one swap of two cards, we can transform the row into the ordered sequence abc.
We are asked to navigate a directed acyclic graph (DAG) from vertex 1 to vertex n, collecting cards and props along the way, and then maximize our total “power” at the end. Cards have both HP and damage, and their power is the product of the two.
We are asked to count permutations of numbers from 1 to n that avoid certain ordered subarrays. More concretely, for each index l, we are given a number ml, and any contiguous segment starting at l and ending at r ≤ ml must not be a consecutive permutation of [l, l+1, ..., r].
We have a simple linear chain of cities numbered from 0 to n, connected sequentially by n roads. Each road has a "beauty" value, which determines the probability that Jellyfish will traverse it if she stands at one of its endpoints.
We are asked to analyze a variant of quicksort where the first element is always chosen as the pivot. For any array, the "time" the function takes is defined recursively as the size of the array plus the time taken by the recursive calls on elements smaller and larger than the…
We are asked to transform a pair of non-negative integers (x, y) from an initial state (a, b) to a target state (c, d) using a small set of bitwise operations. The operations available are x := x & y, x := x The constraints are significant.
We have two players, Jellyfish and Gellyfish, each with a collection of green apples. Jellyfish has n apples with values stored in array a, and Gellyfish has m apples with values stored in array b. They play a game for k rounds.
We are given a directed acyclic graph in a very specific form: every edge goes from a smaller numbered city to a larger numbered city. This means the graph is already topologically sorted by vertex index. We start at city 1 and want to reach city n.
The condition $abc=1$ suggests eliminating one variable from denominators by rewriting powers of $a,b,c$ in terms of the other two variables.
Chaneka is trying to master a challenging video game level divided into n sequential parts. She starts with some familiarity value for each part, given as an array a of size n.
We are asked to pick exactly k clownfish from a sequence of n available fish, each with a given size. Each fish can be assigned either a female or male gender at the time of selection, but the genders follow strict sequence rules.
We are given a tree where every edge is either already directed or still undirected. The task is to decide two things for the undirected edges: their directions and a color assignment for every edge. Directed edges already come with a fixed direction but still need a color.
We are given an array of integers, and our task is to assign each element one of two colors, blue or red. The goal is to count all colorings that satisfy two conditions.
We are given an array of positive integers a of length n. The task is to perform a sequence of "circle" operations on elements of a. Each operation selects an element by its index and "circles" it, and we can circle the same element multiple times.
We are asked to distribute an announcement among $n$ residents at minimum cost. Pak Chanek can notify any resident directly at cost $p$, and each resident who receives the announcement can forward it to a limited number of other residents $ai$, paying $bi$ per share.
We are given an array of integers representing values at different positions. Chaneka can select one or more indices to color black. After that, every element at a position that is a multiple of a black index turns green.
We have a round-robin football tournament with $n$ teams. Every pair of teams plays exactly one match. For each team, its efficiency is defined as: $$text{goals scored} - text{goals conceded}$$ After the tournament finishes, the efficiencies of all teams are computed.
We are given a tree where each vertex carries a small integer value. For any two vertices $u$ and $v$, we define a function that aggregates all values along the unique simple path between them using bitwise OR. This produces a single number summarizing the entire path.
We are maintaining a single integer that changes over time, and after each update we need to answer whether it is possible to “complete” it into a very specific divisor structure using an auxiliary number that shares no prime factors with the current value.
We are given an array of integers and multiple queries. Each query specifies a starting index $l$ and a threshold $k$. The task is to find the largest ending index $r ge l$ such that the bitwise AND of the subarray from $al$ to $ar$ is at least $k$.
We are given a string indexed from 1 to n, and the index range is partitioned into k consecutive segments. Each segment i covers a continuous interval from li to ri, and these segments exactly tile the entire string without gaps or overlaps. We then process a sequence of queries.
We are asked to build a strictly increasing array of length $n$, where each element is a positive integer, and $n ge 3$.
The problem asks whether, given an array of integers and a target integer $k$, there exists at least one contiguous subarray in which $k$ is the element that appears more frequently than any other element.
The problem asks whether we can pick exactly k distinct integers from the set {1, 2, ..., n} such that their sum equals x. Each test case provides three integers: n, the upper bound of the numbers we can choose; k, the number of elements we must select; and x, the target sum.
We are given several independent game configurations, each describing a set of heroes. Each hero has two parameters: health and armor. The game proceeds in discrete rounds, and in every round we choose a fixed damage value x that stays constant for the entire simulation.
We have a weightlifting competition with n athletes. Athlete i has strength si and endurance ei. A barbell weight w is chosen. Any athlete whose strength is less than w cannot lift the barbell at all. Any athlete whose strength is at least w lifts it exactly ei times.
We are given an array of non-negative integers. For every subarray $[l,r]$, we compute the XOR of all elements inside that subarray. Let that XOR value be $f(l,r)$. The contribution of a subarray is not just its XOR.
We are given a rooted tree with $n$ vertices, where vertex 1 is the root. Each vertex $i 1$ has a parent $pi$, so the tree is naturally defined by this parent array.
We are given a binary string, and we are allowed to delete characters from arbitrary positions. After deleting some characters, we want the remaining string to be alternating, meaning no two adjacent characters are equal.
We are given an $n times n$ grid and two arrays $a$ and $b$, each of length $n$. We want to place chips on some cells so that every cell shares a row or column with at least one chip. Placing a chip on cell $(i, j)$ costs $ai + bj$.
We are given a string that is continuously modified and queried. Each modification shifts all characters in a segment forward in the alphabet cyclically, like a Caesar shift applied to a range. After each update, we must answer whether a chosen substring is “valid”.
We are given a tree and a subset of its vertices marked as special. For every vertex $v$, define $f(v)$ as the distance from $v$ to the farthest marked vertex. We want to choose a vertex whose farthest marked vertex is as close as possible.
We are given a sequence of integers, and our goal is to transform it into a "beautiful" sequence using the minimum number of deletions.