text
stringlengths 0
801
|
---|
Each test contains multiple test cases. The first line of input contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The description of the test cases follows.
|
The first line of each test case contains a single integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$.
|
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — the elements of the array $a$.
|
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
|
For each test case, output a single integer — the minimum number of coins needed to make $a$ non-decreasing.
|
In the first test case, $a$ is already sorted, so you don't have to spend any coins.
|
In the second test case, the optimal sequence of operations is:
|
* Choose $k = 2$ and the indices $2$ and $5$: $[ 2, \color{red}{1}, 4, 7, \color{red}{6} ] \rightarrow [2, 2, 4, 7, 7]$. This costs $3$ coins.
|
It can be proven that it is not possible to make $a$ non-decreasing by spending less than $3$ coins.
|
This is the easy version of the problem. The only difference between the two versions is the constraint on $n$. You can make hacks only if both versions of the problem are solved.
|
You are given an array of integers $a$ of length $n$.
|
In one operation, you will perform the following two-step process:
|
1. Choose an index $i$ such that $1 \le i < |a|$ and $a_i = i$. 2. Remove $a_i$ and $a_{i+1}$ from the array and concatenate the remaining parts.
|
Find the maximum number of times that you can perform the operation above.
|
Each test contains multiple test cases. The first line of input contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases. The description of the test cases follows.
|
The first line of each test case contains a single integer $n$ ($1 \le n \le 100$) — the length of the array $a$.
|
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$) — the elements of the array $a$.
|
It is guaranteed that the sum of $n$ over all test cases does not exceed $100$.
|
For each test case, output a single integer — the maximum number of times that you can perform the operation.
|
In the first test case, one possible optimal sequence of operations is $[ 1, 5, \color{red}{3}, \color{red}{2}, 4 ] \rightarrow [\color{red}{1}, \color{red}{5}, 4] \rightarrow [4]$.
|
In the third test case, one possible optimal sequence of operations is $[1, \color{red}{2}, \color{red}{3}] \rightarrow [1]$.
|
This temple only magnifies the mountain's power.
|
Badeline
|
This is an interactive problem.
|
You are given two positive integers $n$ and $m$ ($\bf{n \le m}$).
|
The jury has hidden from you a rectangular matrix $a$ with $n$ rows and $m$ columns, where $a_{i,j} \in \\{ -1, 0, 1 \\}$ for all $1 \le i \le n$ and $1 \le j \le m$. The jury has also selected a cell $(i_0, j_0)$. Your goal is to find $(i_0,j_0)$.
|
In one query, you give a cell $(i, j)$, then the jury will reply with an integer.
|
* If $(i, j) = (i_0, j_0)$, the jury will reply with $0$. * Else, let $S$ be the sum of $a_{x,y}$ over all $x$ and $y$ such that $\min(i, i_0) \le x \le \max(i, i_0)$ and $\min(j, j_0) \le y \le \max(j, j_0)$. Then, the jury will reply with $|i - i_0| + |j - j_0| + |S|$.
|
Find $(i_0, j_0)$ by making at most $n + 225$ queries.
|
Note: the grader is not adaptive: $a$ and $(i_0,j_0)$ are fixed before any queries are made.
|
Each test contains multiple test cases. The first line of input contains a single integer $t$ ($1 \le t \le 50$) — the number of test cases. The description of the test cases follows.
|
The only line of each test case contains two integers $n$ and $m$ ($1 \le n \le m \le 5000$) — the numbers of rows and the number of columns of the hidden matrix $a$ respectively.
|
It is guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $25 \cdot 10^6$.
|
The hidden matrix in the first test case:
|
$1$| $0$| $1$| $\color{red}{\textbf{0}}$ ---|---|---|--- $1$| $0$| $0$| $1$ $0$| $-1$| $-1$| $-1$ The hidden matrix in the second test case:
|
$\color{red}{\textbf{0}}$ --- Note that the line breaks in the example input and output are for the sake of clarity, and do not occur in the real interaction.
|
For an array $[a_1,a_2,\ldots,a_n]$ of length $n$, define $f(a)$ as the sum of the minimum element over all subsegments. That is, $$f(a)=\sum_{l=1}^n\sum_{r=l}^n \min_{l\le i\le r}a_i.$$
|
A permutation is a sequence of integers from $1$ to $n$ of length $n$ containing each number exactly once. You are given a permutation $[a_1,a_2,\ldots,a_n]$. For each $i$, solve the following problem independently:
|
* Erase $a_i$ from $a$, concatenating the remaining parts, resulting in $b = [a_1,a_2,\ldots,a_{i-1},\;a_{i+1},\ldots,a_{n}]$. * Calculate $f(b)$.
|
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^5$). Description of the test cases follows.
|
The first line of each test case contains an integer $n$ ($1\le n\le 5\cdot 10^5$).
|
The second line of each test case contains $n$ distinct integers $a_1,\ldots,a_n$ ($1\le a_i\le n$).
|
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.
|
For each test case, print one line containing $n$ integers. The $i$-th integer should be the answer when erasing $a_i$.
|
In the second test case, $a=[3,1,2]$.
|
* When removing $a_1$, $b=[1,2]$. $f(b)=1+2+\min\\{1,2\\}=4$. * When removing $a_2$, $b=[3,2]$. $f(b)=3+2+\min\\{3,2\\}=7$. * When removing $a_3$, $b=[3,1]$. $f(b)=3+1+\min\\{3,1\\}=5$.
|
For an array $u_1, u_2, \ldots, u_n$, define
|
* a prefix maximum as an index $i$ such that $u_i>u_j$ for all $j<i$; * a suffix maximum as an index $i$ such that $u_i>u_j$ for all $j>i$; * an ascent as an index $i$ ($i>1$) such that $u_i>u_{i-1}$.
|
You are given three cost arrays: $[a_1, a_2, \ldots, a_n]$, $[b_1, b_2, \ldots, b_n]$, and $[c_0, c_1, \ldots, c_{n-1}]$.
|
Define the cost of an array that has $x$ prefix maximums, $y$ suffix maximums, and $z$ ascents as $a_x\cdot b_y\cdot c_z$.
|
Let the sum of costs of all permutations of $1,2,\ldots,n$ be $f(n)$. Find $f(1)$, $f(2)$, ..., $f(n)$ modulo $998\,244\,353$.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.