knightnemo commited on
Commit
4969bcd
·
verified ·
1 Parent(s): d70543b

Upload code_segments/segment_358.txt with huggingface_hub

Browse files
Files changed (1) hide show
  1. code_segments/segment_358.txt +19 -0
code_segments/segment_358.txt ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Alice mixed up the words transmutation and permutation! She has an array $a$ specified via three integers $n$, $b$, $c$: the array $a$ has length $n$ and is given via $a_i = b\cdot (i - 1) + c$ for $1\le i\le n$. For example, if $n=3$, $b=2$, and $c=1$, then $a=[2 \cdot 0 + 1, 2 \cdot 1 + 1, 2 \cdot 2 + 1] = [1, 3, 5]$.
2
+
3
+ Now, Alice really enjoys permutations of $[0, \ldots, n-1]$$^{\text{∗}}$ and would like to transform $a$ into a permutation. In one operation, Alice replaces the maximum element of $a$ with the $\operatorname{MEX}$$^{\text{†}}$ of $a$. If there are multiple maximum elements in $a$, Alice chooses the leftmost one to replace.
4
+
5
+ Can you help Alice figure out how many operations she has to do for $a$ to become a permutation for the first time? If it is impossible, you should report it.
6
+
7
+ $^{\text{∗}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $0$ to $n-1$ in arbitrary order. Please note, this is slightly different from the usual definition of a permutation. For example, $[1,2,0,4,3]$ is a permutation, but $[0,1,1]$ is not a permutation ($1$ appears twice in the array), and $[0,2,3]$ is also not a permutation ($n=3$ but there is $3$ in the array).
8
+
9
+ $^{\text{†}}$The $\operatorname{MEX}$ of an array is the smallest non- negative integer that does not belong to the array. For example, the $\operatorname{MEX}$ of $[0, 3, 1, 3]$ is $2$ and the $\operatorname{MEX}$ of $[5]$ is $0$.
10
+
11
+ Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^5$). The description of the test cases follows.
12
+
13
+ The only line of each test case contains three integers $n$, $b$, $c$ ($1\le n\le 10^{18}$; $0\le b$, $c\le 10^{18}$) — the parameters of the array.
14
+
15
+ For each test case, if the array can never become a permutation, output $-1$. Otherwise, output the minimum number of operations for the array to become a permutation.
16
+
17
+ In the first test case, the array is already $[0, 1, \ldots, 9]$, so no operations are required.
18
+
19
+ In the third t