B. Array Reconstructing

Codeforces
IDCF10153B
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
You are given an array a consisting of n elements a1, a2, ..., an. Array a has a special property, which is: You are given the array a with some lost elements from it, each lost element is replaced by -1. Your task is to find all the lost elements again, can you? The first line contains an integer T, where T is the number of test cases. The first line of each test case contains two integers n and m (1 ≤ n ≤ 1000) (1 ≤ m ≤ 109), where n is the size of the array, and m is the described modulus in the problem statement. The second line of each test case contains n integers a1, a2, ..., an ( - 1 ≤ ai < m), giving the array a. If the ith element is lost, then ai will be -1. Otherwise, ai will be a non-negative integer less than m. It is guaranteed that the input is correct, and there is at least one non-lost element in the given array. For each test case, print a single line containing n integers a1, a2, ..., an, giving the array a after finding all the lost elements. It is guaranteed that an answer exists for the given input. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use _scanf/printf_ instead of _cin/cout_ in C++, prefer to use _BufferedReader/PrintWriter_ instead of _Scanner/System.out_ in Java. ## Input The first line contains an integer T, where T is the number of test cases.The first line of each test case contains two integers n and m (1 ≤ n ≤ 1000) (1 ≤ m ≤ 109), where n is the size of the array, and m is the described modulus in the problem statement.The second line of each test case contains n integers a1, a2, ..., an ( - 1 ≤ ai < m), giving the array a. If the ith element is lost, then ai will be -1. Otherwise, ai will be a non-negative integer less than m.It is guaranteed that the input is correct, and there is at least one non-lost element in the given array. ## Output For each test case, print a single line containing n integers a1, a2, ..., an, giving the array a after finding all the lost elements.It is guaranteed that an answer exists for the given input. [samples] ## Note As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use _scanf/printf_ instead of _cin/cout_ in C++, prefer to use _BufferedReader/PrintWriter_ instead of _Scanner/System.out_ in Java.
**Definitions** Let $ T \in \mathbb{Z} $ be the number of test cases. For each test case $ k \in \{1, \dots, T\} $: - Let $ n_k \in \mathbb{Z} $ be the length of the array. - Let $ m_k \in \mathbb{Z} $ be the modulus. - Let $ A_k = (a_{k,1}, a_{k,2}, \dots, a_{k,n_k}) $ be the array, where each $ a_{k,i} \in \{-1\} \cup \{0, 1, \dots, m_k - 1\} $. - Let $ I_k^{\text{known}} = \{ i \in \{1, \dots, n_k\} \mid a_{k,i} \ne -1 \} $ be the indices of known elements. - Let $ I_k^{\text{lost}} = \{ i \in \{1, \dots, n_k\} \mid a_{k,i} = -1 \} $ be the indices of lost elements. **Constraints** 1. $ 1 \le T \le 1000 $ 2. For each $ k \in \{1, \dots, T\} $: - $ 1 \le n_k \le 1000 $ - $ 1 \le m_k \le 10^9 $ - $ -1 \le a_{k,i} < m_k $ for all $ i \in \{1, \dots, n_k\} $ - $ I_k^{\text{known}} \ne \emptyset $ **Objective** Reconstruct $ A_k $ by replacing each $ a_{k,i} = -1 $ with a value $ x_i \in \{0, 1, \dots, m_k - 1\} $ such that the entire array satisfies the unspecified "special property" (implied to be periodicity or congruence modulo $ m_k $, but not formally defined). **Note**: Since the "special property" is not mathematically defined in the problem, the reconstruction objective cannot be formally specified beyond: > Find $ A_k' = (a_{k,1}', \dots, a_{k,n_k}') $ such that $ a_{k,i}' = a_{k,i} $ for $ i \in I_k^{\text{known}} $, and $ a_{k,i}' \in \{0, 1, \dots, m_k - 1\} $ for $ i \in I_k^{\text{lost}} $, and the array satisfies the (unstated) property that guarantees a unique solution. **Output** For each test case $ k $, output $ A_k' $.
API Response (JSON)
{
  "problem": {
    "name": "B. Array Reconstructing",
    "description": {
      "content": "You are given an array a consisting of n elements a1, a2, ..., an. Array a has a special property, which is:  You are given the array a with some lost elements from it, each lost element is replaced ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10153B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given an array a consisting of n elements a1, a2, ..., an. Array a has a special property, which is: \n\nYou are given the array a with some lost elements from it, each lost element is replaced ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case $ k \\in \\{1, \\dots, T\\} $:  \n- Let $ n_k \\in \\mathbb{Z} $ be the length of the array.  \n- Let $ m_k \\in \\ma...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments