brain
tamnd's digital brain — notes, problems, research
41650 notes
We are given a sequence of integers representing symbols on an ancient tablet. Each test case asks us to count the number of continuous segments (subarrays) of this sequence that satisfy two conditions: the segment contains exactly k distinct numbers, and its length is at…
We are given an array of length $n$ where each element is either $-1$, $0$, or $1$. We are allowed to increment any element by one any number of times. The goal is to make the product of all elements strictly positive while performing the fewest possible operations.
We are given an even-length array of integers representing participants in a show. The task is to form pairs of participants such that each participant is in exactly one pair, and the difference between the two numbers in a pair is minimized in a global sense.
We are given an array of integers, each between 0 and n, and a target number k. We can replace any element with any integer from 0 to n in a single operation. Our goal is to make the MEX of the array equal to k using the minimum number of replacements.
We are asked to count how many binary strings of fixed length and fixed composition can be formed such that two conditions hold simultaneously: the string must dominate a given reference string in lexicographic order, and it must admit at least one split point where both…
We are given a connected simple undirected graph. The graph is already partially filled with edges, and our goal is to make it a complete graph, meaning every pair of distinct vertices must end up connected by an edge. We are not allowed to directly add edges.
We are given a hidden array of length $2n-1$ that contains each number from 1 to $n$ exactly twice, except for a single number which appears only once. Our goal is to determine which number appears only once. We do not need to know its position, only its identity.
We are given a hidden array of length 2n-1, containing integers from 1 to n such that every number appears exactly twice except for one number that appears only once. Our goal is to identify the number that occurs exactly once. We do not need its position, only its value.
We start with n people placed on positions 1 through n on a line. The initial configuration is completely rigid: person i starts at position i.
We are asked to count the number of ways to color cells black in an $n times n$ grid given a list $a$ of length $n$. The entry $ak$ specifies how many black cells must appear in row $k$.
We are asked to analyze a situation where two players, Alice and Bob, pick objects from a shop in turn. Each object has a value from our perspective, and each player has their own preference order.
We are given a line of $10^9$ cells, each either black or white. Initially, a certain set of cells are black, and all others are white.
We are given a tree with n vertices, each edge has a positive weight. The task is to assign nonnegative integer weights to the vertices themselves so that when we compute the minimum cost of a “victorious coloring” (coloring vertices red or yellow with at least one red)…
We are given a tree with weighted edges, and we are asked to assign nonnegative weights to vertices so that a certain “victorious coloring” has a minimum cost at least some value l, while keeping the sum of vertex weights as small as possible.
We are given a sorted sequence of attack timestamps. Each query gives a contiguous segment of this sequence, and inside that segment we are allowed to delete some elements. The goal is to keep as many timestamps as possible while avoiding a specific failure condition.
We are given a rooted tree with root fixed at vertex 1. Some vertices are marked as “active” (contain a monster), others are not.
We are given an array of zeros of length $n$, and a target array of positive integers. We want to reach the target array with as few operations as possible. There are two operations available. The first, Increase, adds the same positive integer to every element of the array.
We are given a hidden permutation of length $n^2 + 1$ and we need to find a monotone subsequence of length exactly $n+1$. The subsequence can either be increasing or decreasing.
We are given an array where every element starts at least 2, and two players repeatedly modify it until every value becomes 1.
We are asked to compute the maximum number of turns the Krug can survive against Doran on a square grid. The grid has coordinates from 0 to n in both rows and columns. The Krug moves first, either staying in place or moving to a vertically or horizontally adjacent cell.
We are given a binary array, meaning each element is either 0 or 1, and we need to repeatedly remove triples of identical elements. Each removal has a cost defined as the minimum distance between consecutive elements in the triple.
We are given an array a of length n that satisfies a special property called "cute," which prevents certain repeating patterns of four indices.
We are given a circular sequence of integers, and we are allowed to change each value by paying unit cost per increment or decrement.
We are asked to work with trailing zeros of factorials in arbitrary bases. Specifically, for any integer $xge 1$ and base $kge 2$, $vk(x!)$ counts how many times $k$ divides $x!$. For prime bases, this is straightforward: sum the integer divisions of $x$ by powers of $p$.
We are given several collections of stick lengths, and for each collection we want to pick some of these sticks to form the sides of a polygon. Each chosen stick becomes exactly one side, so we are not allowed to split or merge sticks.
We are given a circle of apple trees, each bearing a single apple with an associated beauty value. You start at tree one and walk around the circle repeatedly. At each tree, you have the choice to eat the apple or skip it.
We are asked to determine whether it is possible to construct three non-negative integers, $a$, $b$, and $c$, such that their pairwise bitwise ANDs equal three given integers $x$, $y$, and $z$. Specifically, the constraints are that $a & b = x$, $b & c = y$, and $a & c = z$.
We are asked to count the number of ways to fill in missing values in a partially specified permutation such that the resulting permutation can be split into two consecutive subsequences whose combined order gives the sorted permutation from $1$ to $n$.
We are given an array of length $n$ that is supposed to be a permutation of $1 dots n$, but some positions are unknown and marked as $-1$.
The tree represents a world where a cat starts at node 1 and tries to reach node n. You cannot directly control the cat’s path when it moves.
We are given an array of positive integers. We are allowed to choose one odd length $x$, and then repeatedly perform an operation up to $k$ times. Each operation picks any subsequence of length $x$, computes its median, and overwrites all chosen elements with that median value.
We are given an array of integers a, where each element behaves like a “value sitting on a position”, and a second array b which describes how expensive it is to increase each corresponding a[i] by 1.
We are given an array of integers and want to transform it into a zigzag sequence. A zigzag array is one where each element alternates between being smaller and larger than its neighbor: the first element is smaller than the second, the second is larger than the third, and so on.
We are given a binary string consisting of 0s and 1s and a positive integer k. Each 1 in the string can be “turned off” by Teto according to a simple local rule: if a 1 is not protected and there are no other 1s in the previous k-1 positions, it can be changed to 0.
We are given an array of positive integers a of length n. For each element ai, we can increment it by 1 any number of times at a cost of 1 per increment.
We are asked to analyze a two-player game on an $n times m$ grid. Each cell can contain tokens, and on a turn, a player picks a token and moves it along a sequence of adjacent cells that always steps leftwards in columns, ultimately depositing new tokens along that path and…
We are given a tree with n nodes, where each node contains a set of colors drawn from a palette of size k. Each node's set may be different, and the total number of color assignments across all nodes is s.
We are given a set of n batteries, some of which work and some of which don't. We do not know how many work, but we do know that at least two do. There is a flashlight that requires exactly two working batteries to turn on.
Each wizard sits at a fixed position from 1 to n, and each one chooses a direction for his cape: either left or right. This choice determines from which positions he becomes visible.
We are asked to design a maze on an $n times n$ grid where each cell contains an arrow pointing in one of the four cardinal directions: up, down, left, or right. Abraham, starting from any cell, follows the arrow in that cell to the next cell and continues moving in this fashion.
We are asked to compute the total number of matches in a modified double-elimination football tournament. In this tournament, teams start in a winners' group. Each round, winners' group teams pair up and play matches.
We are given a permutation of integers from 1 to $n$. The allowed operation selects three indices $i < j < k$ such that the value at $i$ is exactly one more than the maximum of $pj$ and $pk$ and exactly two more than the minimum of $pj$ and $pk$.
We start with a permutation of length $n$, meaning every integer from $1$ to $n$ appears exactly once in some order.
We are given a list of numbers and two players who interact with it in a turn-based process. The key twist is that the final outcome is not chosen directly, but emerges from a game where one player removes elements from consideration and the other permanently freezes elements…
We are given a hidden permutation of integers from 1 to $n$, but we only have direct access to the first $n-1$ elements through an interactive query.
We are given a collection of integers on a whiteboard and two operations to modify it. The first operation, Erase, allows us to remove up to $k$ numbers.
We have a circular arrangement of up to 20 machines, each of which either decreases an integer by one (type A) or halves it and floors the result (type B).
We are repeatedly shrinking a pile of pizza slices using a very specific rule until only a tiny remainder is left. The process is deterministic in structure but flexible in how we split the pile, and our only freedom is how we choose that split each day.
In Hyper Smawk Bros, two players take turns attacking a boss with health n. Each attack reduces the health by an integer damage x between 1 and m. The catch is that on your turn, you cannot repeat the exact damage your opponent used on the previous turn.
We are asked to construct permutations of size $n$ that satisfy two independent structural constraints, and then output as many distinct valid permutations as exist, capped at 2000.
We are asked to simulate a sequence of missions that guarantees our skill reaches at least a target value n regardless of our starting skill s, which is unknown and can be any integer from 1 to n. Each mission has a difficulty y and a duration l.
We are dealing with a hidden array of integers, where each integer is in the range [0, 2^30). We are allowed to ask queries about contiguous subarrays.
We are managing a fleet of drones, each with an initial energy level. The rule is that no energy level should appear more than k times.
We are asked to construct an array of length $n$, where each position holds a non-negative integer, such that a collection of interval constraints is satisfied.
We are given an array of integers, and the goal is to make it "balanced." An array is balanced if each number x that appears in it does so exactly x times. So if a number appears too few or too many times, we need to remove some elements to fix it.
We are given a hidden integer position $p$ that will eventually be chosen somewhere inside a fixed interval $[l, r]$. We do not know the exact value, and our goal is to prepare a strategy before seeing $p$.
We have an infinite 2D grid with a black cell initially at the origin (0, 0). We perform a sequence of expansion operations, each either type "4" or type "8".
We are asked to construct a sequence of length $n$, where each element is a positive integer up to $10^{18}$, with a very specific constraint on neighboring pairs. For every adjacent pair $(ai, a{i+1})$, we compute its gcd.
We are asked to construct a sequence of length $n$, where each element is a large positive integer, and the goal is to control the structure of greatest common divisors between consecutive elements. For every adjacent pair $(ai, a{i+1})$, we compute $gcd(ai, a{i+1})$.
We are given a 2D grid of size $n times m$, where each cell contains a positive integer. We can construct "holes" in cells. A cell is considered a sink either if it has a hole, or if it is adjacent (sharing a side) to another sink with a smaller or equal value.
We are given two binary strings of equal length. Think of them as two rows of switches, where each position is either off or on. The task is to transform the first row into the second by repeatedly choosing a segment and flipping all bits in that segment.
We are given an array of length $2n$. We must split its elements into two subsequences $p$ and $q$, each containing exactly $n$ elements. Order inside a subsequence does not matter, only the multiset of chosen values matters.
We are given an array $a$ and another array $b$ of the same length. Two players alternate turns for exactly $k$ moves. On each move, the current player picks an index and either adds or subtracts the corresponding value $bi$ from $ai$.
We are given a football match with a fixed number of players, and a sequence of disciplinary actions in the form of yellow and red cards. Each yellow card contributes toward a potential suspension, and each red card immediately suspends a player.
We are given a permutation grid of size $n times n$, where every number from $1$ to $n^2$ appears exactly once. Instead of directly using this grid, we interact with a hidden process that defines, for each snake length $l$ and time $T$, a value $f(l,T)$.
We are given a quadratic polynomial in one variable, and we repeatedly raise it to a power that changes per query.
We are asked to partition a sequence of positive integers into contiguous subarrays such that each subarray has a cost defined by the ratio of its last element to its minimum element, rounded up. Formally, for a subarray $b$, the cost is $lceil bk / min(b1, dots, bk) rceil$.
We are asked to work with sequences of positive integers. For any contiguous subsequence $b$ of a sequence $a$, there is a notion of cost: it is the ceiling of the last element of $b$ divided by the minimum of all elements in $b$.
We are tasked with reconstructing a hidden sequence of length $2n$ in which each number from $1$ to $n$ appears exactly twice. The only tool we have is the MAD query.
We are given a polynomial $f(x)$ of degree $n$ where some coefficients are known and others are undetermined (represented by $-1$).
We are given a grid filled with zeros and ones. For every cell in this grid, we want to know the smallest possible “valid rectangle” that covers it, where validity is defined in a very specific way: the rectangle must have ones at all four corners, not necessarily inside.
We are given a multiset of integers, and we are allowed to split it into several smaller multisets such that every original element is used exactly the same number of times overall. In other words, we are partitioning occurrences of numbers into groups.
We are given two arrays, one of length $n$ and one of length $m$, and together they contain every number from $1$ to $n+m$ exactly once. You can think of the elements as being split into two buckets. We then simulate a long sequence of $k$ steps.
We are given a binary string where some positions are fixed as 0 or 1, while others are unknown and can be chosen freely. Once we assign values to all unknowns, we obtain a fully concrete binary array of length n.
We are given an array of integers and, for each query value X, we are allowed to increase individual elements of the array by repeatedly adding one. Each query is independent, and we always start from the same initial array.
We are asked to compute a global sum over all subsets of vertices in a tree. The input is an unweighted tree with n vertices. From this tree, we imagine a complete graph where the weight between any two vertices equals the distance between them in the original tree.
We are given an array and we are allowed to delete elements from it. After deletions, we want the remaining sequence to satisfy a very specific restriction: it must not contain two elements where the later element is exactly one larger than the earlier element.
We are asked to maximize bonus points in a store where every purchase can potentially increase our loyalty level. Each item has a price between 1 and some loyalty factor $X$. Initially, our loyalty level is calculated as the integer division of our total spend $S$ by $X$.
We are given an $n times n$ grid with black cells marked and white cells marked .. Our goal is to paint some white cells black so that three conditions are met simultaneously. First, there must be at least one black cell.
We are simulating a sequence of contest rounds where a participant can sometimes adjust their rating before each rated round.
We are given an array whose values are fixed, but we are allowed to permute them arbitrarily before answering queries. Alongside this array, we are also given several index ranges.
We are asked to construct a labeled tree with $n$ vertices such that the sum of the products of the labels of each edge is a perfect square. Formally, if the tree has edges $(u, v)$, we compute $S = sum (u cdot v)$, and $S$ must equal $x^2$ for some integer $x$.
We are given several test cases. In each test case, we must construct a permutation of the numbers from 0 to n−1. Think of this permutation as placing each number exactly once on a line of length n. On top of this array, we are given m intervals.
We are given an array of integers between 1 and n and an integer k. We are allowed to append exactly k numbers to the end of this array.
We are given a hidden permutation of size $n$, meaning it contains each number from $1$ to $n$ exactly once. After this permutation was fixed, someone chose a segment $[l, r]$ and increased every element inside that segment by exactly one.
We are given two integers a and b. We can repeatedly pick an integer x such that 0 ≤ x ≤ a (the current value of a) and replace a with a XOR x.
We are given a binary string s of length n, which means it contains only '0' and '1'. The task is to select a subsequence p from s such that two conditions hold: first, p must be non-decreasing (so all '0's must appear before any '1's in p), and second, if we remove all…
We are given an array of integers, each between 1 and 10, and we are asked to find the maximum average of any contiguous subarray. A subarray is simply a consecutive segment of the array, which can be as short as a single element or as long as the entire array.
We are dealing with a two-phase interactive problem. In the first phase, Player A receives a full $n times n$ binary grid, where each cell is either a 0 or a 1, and each test case also specifies whether the grid is fully connected through 1s or not.
We are given a hidden permutation of the integers from 0 to n−1, and a collection of fixed segments of this permutation. For each segment, we are interested in its mex, the smallest non-negative integer that does not appear inside that segment.
We are given a hidden permutation of integers from 0 to n-1, and our task is to find the maximum MEX over a set of ranges. Each range specifies a contiguous segment of the permutation, and the MEX of a range is the smallest non-negative integer missing from that segment.
We are given a sequence of integers, and two players take turns acting on consecutive pairs of elements. On each turn, the current player may either skip or swap the current element with the next.
We are given a permutation of integers from 1 to $n$, and a binary string $x$ of the same length. Initially, we have another binary string $s$ of zeros.
We are given a 2-row grid with $n$ columns, where each cell contains a distinct integer from $1$ to $2n$. For any interval of integers $[l, r]$, we can generate a binary grid where a cell is marked 1 if its original value falls inside that interval, otherwise 0.
We are given a long base string and many independent queries, each asking about a contiguous segment. For any queried segment, we are interested in all substrings that are palindromes and that appear at least twice inside that segment.
We are dealing with a hidden tree on $n$ labeled vertices, but we cannot see its edges directly. Instead, we can “probe” the tree using permutations. Each query is a full ordering of the vertices.
We are given a rooted tree where every vertex has a fixed parent, and thus a fixed ancestor structure. Alongside this tree, each vertex $u$ comes with a target number $au$.
We are given a rooted tree with $n$ nodes, labeled from $1$ to $n$, with node $1$ as the root. For each node $u$, a number $au$ is specified.
We are given an undirected connected graph with vertices and weighted edges. We start at vertex 1 and must traverse the graph such that every edge is marked at least once, returning to the start.
We start with a string s and want to turn it into another string t, both of the same length. The only allowed move does not directly edit characters; instead, it rebuilds the entire string at once using a very constrained rule.