H. King

Codeforces
IDCF10247H
Time2000ms
Memory256MB
Difficulty
English · Original
Formal · Original
As we all know, the number of _Pang_'s papers follows exponential growth. Therefore, we are curious about _King_ sequence. You are given a prime $p$. A sequence $(a_1, a_2, \\dots, a_n)$ is a _King_ sequence if and only if there is an integer $1 <= q < p$ such that for all integers $i in [ 2, n ]$, $q a_{i -1} equiv a_i pmod p$. Given a sequence $B = (b_1, \\dots, b_m)$, what is the length of the longest _King_ subsequence of $B$? A subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. $P a n g$ is super busy recently, so the only thing he wants to know is whether the answer is greater than or equal to $frac(n, 2)$. If the length of the longest _King_ sequence is less than $frac(n, 2)$, output $-1$. Otherwise, output the length of the longest _King_ subsequence. The first line contains an integer $T$ denoting the number of test cases ($1 <= T <= 1000$). The first line in a test case contains two integers $n$ and $p$ ($2 <= n <= 200000$, $2 <= p <= 1000000007$, $p$ is a prime). The sum of $n$ over all test cases does not exceed $200000$. The second line in a test case contains a sequence $b_1, \\dots, b_n$ ($1 <= b_i < p$). For each test case, output one line containing the answer which is $-1$ or the length of the longest _King_ subsequence. ## Input The first line contains an integer $T$ denoting the number of test cases ($1 <= T <= 1000$).The first line in a test case contains two integers $n$ and $p$ ($2 <= n <= 200000$, $2 <= p <= 1000000007$, $p$ is a prime). The sum of $n$ over all test cases does not exceed $200000$.The second line in a test case contains a sequence $b_1, \\dots, b_n$ ($1 <= b_i < p$). ## Output For each test case, output one line containing the answer which is $-1$ or the length of the longest _King_ subsequence. [samples]
**Definitions** Let $ p $ be a prime. A sequence $ (a_1, a_2, \dots, a_n) $ is a *King sequence* if there exists an integer $ q \in [1, p-1] $ such that for all $ i \in [2, n] $, $$ a_i \equiv q \cdot a_{i-1} \pmod{p}. $$ Given a sequence $ B = (b_1, b_2, \dots, b_n) $, let $ \mathcal{K}(B) $ denote the set of all King subsequences of $ B $. **Constraints** 1. $ 1 \le T \le 1000 $ 2. For each test case: - $ 2 \le n \le 200000 $, $ 2 \le p \le 1000000007 $, $ p $ prime - $ 1 \le b_i < p $ for all $ i \in \{1, \dots, n\} $ - Total sum of $ n $ across test cases $ \le 200000 $ **Objective** For each test case, compute: $$ L = \max \{ |S| \mid S \in \mathcal{K}(B) \} $$ If $ L < \left\lceil \frac{n}{2} \right\rceil $, output $ -1 $. Otherwise, output $ L $.
API Response (JSON)
{
  "problem": {
    "name": "H. King",
    "description": {
      "content": "As we all know, the number of _Pang_'s papers follows exponential growth. Therefore, we are curious about _King_ sequence. You are given a prime $p$. A sequence $(a_1, a_2, \\\\dots, a_n)$ is a _King_ ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10247H"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "As we all know, the number of _Pang_'s papers follows exponential growth. Therefore, we are curious about _King_ sequence.\n\nYou are given a prime $p$. A sequence $(a_1, a_2, \\\\dots, a_n)$ is a _King_ ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ p $ be a prime. A sequence $ (a_1, a_2, \\dots, a_n) $ is a *King sequence* if there exists an integer $ q \\in [1, p-1] $ such that for all $ i \\in [2, n] $,  \n$$\na_i \\equiv q \\...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments