brain
tamnd's digital brain — notes, problems, research
43815 notes
We are given a binary array that evolves through a merging game. Two players, Alice and Bob, alternate turns. On each turn, a player selects a contiguous segment of length at least two, removes it, and replaces it with a single value derived from that segment.
We have a rooted tree whose leaves each contain exactly one cherry. A shake performed at vertex v makes the cherries fall from every leaf inside the subtree of v. Once a cherry has fallen, it must never be affected by another shake.
We are given an array of integers placed on a line, and we must support two operations: point updates and range queries. The interesting part is not the update itself, but how a special property behaves over a segment.
Working
We are given a permutation of length $n$, which is simply an array of integers from $1$ to $n$ in some order without repeats.
Vadim has an hourglass that measures exactly s minutes. He flips it initially, and after every k minutes, he flips it again, regardless of whether all the sand has fallen. If the sand finishes before the next flip, he waits until the scheduled flip time.
We have $n$ people. They must be partitioned into teams, where every team has either 2 or 3 members. After the teams are formed, each team independently chooses one of two civilizations.
Andrei starts with a single pile containing $n$ apples. He can split any pile of size $x$ into two smaller piles in exactly one minute, creating one pile of $lfloor x/2 rfloor$ apples and another of $lceil x/2 rceil$ apples.
The tournament has a surprisingly simple structure once we stop thinking about individual matches. Whenever a cow survives a match, its new skill becomes the sum of the two participants.
We are given multiple arrays and are allowed to perform a single operation: choose an element from one array, move it to the end of another array, and then compute the sum of MEXes of all arrays after this move. The task is to sum the values of all possible such operations.
The tournament can be viewed as a complete binary tree over the array of cows. Each leaf is a single cow. Every internal node represents a contiguous segment of cows. The skill of a node is the XOR of all values inside that segment.
Every robot receives exactly the same sequence of moves. After the first instruction, all robots shift by the same displacement. After the second instruction, all robots shift by another common displacement, and so on.
We start with an array and a sequence of update operations. Each operation adds some value to one position. The unusual part is the crash rule. After every update, if any element of the current array becomes larger than h, the computer immediately crashes.
We are given an array of integers, which may include negative numbers. The task allows us to pick a single integer shift x and add it to every element of the array. After performing this shift, we want to maximize the MEX of the array.
We are asked to generate a sequence of distinct "perfect roots" for each test case. A perfect root is simply an integer $x$ such that $x^2$ is also an integer, which is trivially true for all positive integers.
We are given an array. For every position, we look at the prefix ending there and take the maximum value seen so far. The score of the array is the sum of all those prefix maxima. We may swap any two elements at most once, or choose not to swap at all.
We are asked to reconstruct a permutation $q$ of length $n$ from a special encoding of Cartesian trees derived from a series of arrays.
We are given two DFS preorder traversals of the same set of vertices {0,1,...,n}. The tree itself is unknown. The only thing we know is that in both traversals the root 0 appears first, and for every vertex the order of its children during DFS is arbitrary.
I can write the editorial, but only if I can first reconstruct the solution completely and verify the algorithm. For this particular problem, the official editorial for F2 is unusually terse and omits many crucial details.
We have a sequence of $n+1$ rooms connected by $n$ doors. Each door $i$ has a number $ai$ indicating the exact second it will automatically open, if untouched. Some rooms contain keys at the start according to a binary string $s$, where a 1 means a key exists in that room.
We are given an array of integers, and we are asked to determine the largest integer $k$ such that we can sort the array in non-descending order by swapping any two elements whose difference is at least $k$.
We are asked to analyze a two-player game on a directed graph with $n$ vertices. The graph is almost a chain: for every vertex $u$ from 1 to $n-1$, there is an edge $u to u+1$.
We are given a row of seats represented as a binary string, where 1 indicates a student is sitting there and 0 indicates an empty seat. No two students are adjacent initially.
We have a tree. Vertex i initially contains ai nuts. There are two kinds of electricity costs. The first cost comes from a special redistribution operation. We choose a vertex v. Then every other vertex is processed from larger distance to smaller distance from v.
We are not asked to count permutations directly. The real task is to understand which binary strings $w$ are possible, what value $f(w)$ they produce, and then optimize over all replacements of the question marks.
We are given a binary string s of length n. Our goal is to transform this string into a single character "1" using a special operation: we can take any contiguous substring, and replace it with the character that occurs at least as many times as the other character in that…
We are given a string of length $n$ consisting of 0s and 1s. For a permutation $p$ of $[0, 1, dots, n-1]$, the function $f(w)$ counts the number of permutations such that, for each position $i$, the minimum excluded value (MEX) condition is satisfied: if $wi = 1$, there exists…
We have an array of numbers. We may select any even number of elements from it and partition them into ordered pairs. A pair (x, y) contributes 1 to the table only if row x and column y exist.
We need to construct a permutation of the numbers from 1 to n. For every position i with 2 ≤ i ≤ n-1, there must exist some position j satisfying i ≤ j ≤ n such that $$pi = pj oplus i.$$ Since we are free to choose the entire permutation, this is a constructive problem.
We are asked to help a frog move along an infinite number line from position 0 to a target position $x$. The frog has $n$ types of magical jumps.
I can't reliably write a complete accepted editorial and proof for Codeforces 2190G from the problem statement alone.
We start with a forest. We may add edges between its connected components until the whole graph becomes a single tree. For every resulting tree, run the standard Prüfer-code deletion process: repeatedly remove the smallest numbered leaf until only two vertices remain.
Instead of thinking about medians directly, it is much more useful to think about the permutation being revealed in increasing value order. Suppose we process the values of a permutation from 1 to n. When value x is processed, its position becomes "active".
The official editorial for this problem is exceptionally long and derives a fairly intricate bit-DP from several structural lemmas about XOR products of intervals.
We are asked to interact with a hidden permutation p of size n and produce a permutation q that is lexicographically just larger than p and also satisfies the property that reversing q gives a permutation larger than the reverse of p. The catch is that we never see p directly.
We are asked to compute a sum over all non-empty subsequences of a given bracket sequence. Each subsequence has a “score” defined as the length of its longest regular bracket subsequence that is strictly “better” than itself.
We are given a regular bracket sequence s. A regular bracket sequence (RBS) is one where every prefix contains at least as many '(' as ')', and the total numbers of opening and closing brackets are equal.
We are asked to analyze a two-player game on a binary string, where Alice goes first and Bob follows, taking turns. On their turn, a player may select any strictly non-increasing subsequence of the string and rearrange it to be non-decreasing.
We are asked to color a sequence of distinct integers arranged in a row using two colors so that two conditions hold simultaneously. First, any two adjacent numbers in the original sequence must have different colors.
Each position i contains a pair of values (ai, bi). For that position we have exactly two choices. If we do nothing, the value ai stays in array a and bi stays in array b. If we swap that position, the value bi moves to array a and ai moves to array b.
We are given a tree rooted at node 1, where each node carries a positive integer weight. The cost of the tree, relative to a chosen root, is the sum over all nodes of the product of the node's weight and its distance from that root.
I can write a full editorial only if I first reconstruct the actual solution in detail. For this problem, the official editorial contains a fairly intricate two-phase DP with interval states, probability propagation, prefix/suffix aggregation, and a second DP once the two…
We are given a binary string, which is a sequence of 0s and 1s, and we can perform a very specific operation: pick one index i, and flip every bit in the string except the bit at index i. Flipping means changing 0 to 1 and 1 to 0.
We are given a shooter game scenario where we have a gun with a magazine of n bullets. Each bullet has a fixed damage ai, and bullets are fired in sequence, one per second.
We are given a string consisting of lowercase letters and asked to determine how to rotate it to maximize the number of contiguous blocks of identical letters. A block is defined as a maximal substring of consecutive identical characters.
We are given a tree, which is a connected acyclic graph with $n$ vertices, and each vertex has an associated integer value. The operation we can perform repeatedly is to remove a vertex if the sum of the values of its remaining neighbors differs in parity from its own value.
We are given a tree, which is an undirected, connected, acyclic graph of $n$ vertices. Two hidden vertices, $x$ and $y$, define a unique path because trees have exactly one simple path between any pair of vertices.
The courier starts at $(Ax, Ay)$, must visit every house, and finally reach $(Bx, By)$. The movement rules are unusual. He may move one unit to the right, one unit up, or one unit down. He can never decrease his $x$-coordinate.
We are given an array whose values lie between 1 and n. An element may be reused any number of times, so the only thing that matters is which values are present in the array, not how many times they occur.
We are given a sequence of swords, each having a strength value, and a sequence of monsters, each requiring a certain number of strikes to be defeated. Each sword can be used at most once, because after striking a monster it breaks immediately.
We start with two arrays of the same length. For any position, we may directly overwrite a[i] with b[i]. We may also copy values from right to left by replacing a[i] with the current value of a[i+1]. Each query asks for the largest possible sum on a subarray a[l..
We are given a permutation of numbers from 1 to n, which means every number in this range appears exactly once. We are allowed to choose a single continuous segment of this permutation and reverse it.
We are given an array of integers and a fixed increment value. In one move, we can pick any position in the array and increase that single element by exactly the same amount each time. We can repeat this operation as many times as we want on any indices.
We are asked to count certain ways to cut a tree into connected components with a specific property. The tree has n vertices, each with a value av. We are also given a small set of numbers b1, ..., bk.
We have a rectangular grid. Every cell contains an integer value, positive or negative. Michelangelo chooses a path from the top-left corner to the bottom-right corner. He may only move right or down.
We are given a grid of size $n times m$ filled with zeros and ones. We need to make a cut from the top-left corner to the bottom-right corner, moving only right or down.
We are given a tree with n vertices, where each vertex has a non-negative integer av written on it. We are also given a set of k distinct non-negative integers b1, ..., bk.
We are given several independent scenarios. In each scenario, there are multiple bank accounts, each holding some amount of money.
We are given multiple strips of paper, each of the same length, containing lowercase letters. Each column across the strips represents a choice: the letter at that column in the decrypted message must come from one of the letters in that column of the strips.
We are given a fence made of $n$ unit-width boards arranged in a line. We are allowed to remove any subset of these boards, but doing so creates gaps in the fence. The only constraint is that the removed boards must not form a continuous block of length $w$ or more.
We are given a square grid of points with coordinates from 1 to 3n along both axes, forming a total of $3n times 3n$ points. The task is to select the largest possible set of triangles such that each triangle uses three distinct points from the grid, has an area of exactly 0.
We are given a rooted binary tree where every vertex either has exactly two children or is a leaf. The root is vertex 0, and all other vertices are numbered from 1 to n. A process starts from some vertex v and moves step by step according to a very specific stateful rule.
We are given a set of quadratic functions, each defined by coefficients $ai$, $bi$, and $ci$. Two functions are called independent if they never intersect, which algebraically means their difference is never zero.
We are given a rooted binary tree where vertex 0 is the root and every other vertex is either a leaf or has exactly two children, left and right. The vertices are numbered, and the structure is fully specified by child pointers.
We are given a hidden sequence of integers $a1, a2, dots, an$ and, instead of the sequence itself, we are provided with a function evaluated at each index: $f(x) = sum{i=1}^n ai cdot Given that $n$ can be as large as 300,000 and the total sum over all test cases is also…
We are given a permutation of integers from 1 to n and can perform a specific type of swap: for any index i from 1 to n/2, we can swap the element at position i with the element at position 2i.
We are given a sequence of numbers from 1 to 6, and we are allowed to change any element to any other value from 1 to 6. The goal is to transform the sequence so that every pair of neighboring elements behaves like valid transitions on a standard dice.
We are given several very small collections of integers, each collection containing at most five numbers, and we are asked whether we can pick some non-empty subset whose product is exactly 67. Each test case is independent.
We are asked to construct a graph with a given number of vertices n and edges m such that it cannot be split into two parts where the sums of degrees of each part are equal. The graph must be simple, with no loops or multiple edges.
We are given a source string s and a target string t. We start with an empty string p and want to build it until it becomes exactly equal to t.
We are given a source string s and a target string t. We start with an empty string p, and our only goal is to build p until it exactly matches t.
We are given a string consisting of round brackets "(" and ")", and square brackets "[" and "]". The string has even length.
We are asked to reconstruct a hidden directed acyclic graph (DAG) by interacting with a system that enumerates all paths in lexicographic order. Each query allows us to ask for the $k$-th path.
We are given two integers, $p$ and $q$, representing a fraction $frac{p}{q}$. Alice and Bob play a turn-based game where on each turn a player can decrease $p$ by 1 (if $p 0$) or decrease $q$ by 1 (if $q 1$). Alice goes first.
We are given a directed acyclic graph with up to 15 vertices. The edges are unknown, but we are allowed to probe the graph through an oracle. Each query asks for the k-th path in the lexicographically sorted list of all valid directed paths in the graph.
We are given an array and we want to count pairs of positions where a very specific relationship holds between the values at those positions and their distance in the array.
We are given an integer $x$, and we want to count how many integers $y$ satisfy a very specific balancing condition: if you take $y$ and subtract the sum of its digits, you land exactly on $x$.
We start with a very constrained system: one array begins as all ones, another array is all zeros, and a third array c provides a sequence of target values between 1 and 50.
We are given an array of length $n$ where each element is an integer from $-1$ to $n$. The special value $-1$ is a wildcard that can be replaced by any integer between $0$ and $n$.
We are given an integer array and asked to count subsequences that are "self-produced." A sequence is self-produced if for every element, either the sum of all previous elements equals that element, or the sum of all following elements equals that element.
We are asked to find positions on a rectangular grid where we can place a jammer such that it always intercepts a robot moving from the bottom-left corner $(0,0)$ to the top-right corner $(n,m)$, while remaining invisible at the start and end points.
We are given an initial array $a$, and we want to imagine building a longer array $b$ that contains all elements of $a$ in order (not necessarily consecutively), but between every pair of adjacent elements in $b$, the values must differ by exactly 1.
Alice and Bob play a three-round card game where each round has independent scores between 0 and a maximum k. The first two rounds are already played, with Alice and Bob scoring a1, b1 in round one and a2, b2 in round two.
We are given two arrays, each sorted in non-decreasing order, and each having an odd number of elements. The task is to determine whether we can make the two arrays identical using a sequence of operations.
We are asked to build a grid with exactly two rows and some number of columns. Each cell can either contain a mine or be empty.
We start with two stacks of blocks. The first stack has height a, the second has height b. We want to reach target heights c and d respectively, only by increasing heights. There are two allowed operations. The first operation increases exactly one of the towers by one block.
We are given an array of positive integers, and we define a number as special if the power of 6 that divides it is strictly greater than the power of 7 that divides it.
We are given a starting integer $x$ and a list of $n$ operations, each of which modifies $x$ by either addition, subtraction, multiplication, or division by a positive integer. The twist is that the operations are applied in a random order: all $n!
We are given a collection of particles, each with an energy value and a reactivity limit. A particle's reactivity determines the maximum number of other particles that can coexist with it in the reactor.
We are given a permutation arranged on a line and two special cutting points, called portals. These portals divide the array into segments and define where elements can be extracted from and reinserted.
We are given an array of positive integers and two players who alternate turns, starting with Alice. The game evolves by either ending immediately if the current array is already non-decreasing, or by performing a single allowed operation on a chosen element.
We are given a circular table with n players, each having a certain number of dishes they must eat. Players take turns sequentially around the table, and during a player’s turn, if they have any dishes left, they must eat exactly one.
We are given a string consisting of lowercase letters, and the game involves repeatedly replacing pairs of equal letters with asterisks, provided that all characters between them have already become asterisks.
We are given several independent test cases. In each one, we start with a short array of positive integers and repeatedly remove elements until the remaining array is sorted in non-decreasing order.
We are given a grid of size $n times n$ where each cell can be thought of as a vertex labeled by its row and column $(r,c)$. Two vertices are connected if the squared Euclidean distance between them is exactly 13.
We start with an $n times n$ grid that is completely empty, and we gradually paint some cells black. After each paint operation, we must decide whether the current black-white pattern avoids a very specific forbidden configuration involving two rows and two columns.
We are maintaining an $n times n$ grid that starts completely empty in the sense that every cell is white. Over time, we flip certain cells to black, one at a time, and after each flip we must decide whether the current black-white pattern satisfies a structural restriction…
We are given a string T of even length n, consisting of the characters 'a', 'b', and '?'. The question asks us to count all possible strings S that match T wherever T specifies a character (i.e., S[i] = T[i] when T[i] is not '?
We are given a sequence of integers and a set of queries that modify elements of the sequence. After each modification, we are asked to compute two values derived from the sequence: the maximum length of two subarrays that are permutations of each other, and how many pairs of…
We are given a sequence of integers that has been generated by a very simple algorithm: start with some initial sequence of length m, and repeatedly choose an element and insert its value plus one immediately after it until the sequence reaches length m + k.