J. Three Sorted Arrays

Codeforces
IDCF10058J
Time2000ms
Memory512MB
Difficulty
English · Original
Formal · Original
This time Laltu wanted the question to be straightforward. So, given 3 1-indexed sorted arrays (A[, B[], C[])], find the number of triplets 1  ≤  i  ≤  j  ≤  k, such that: A[i]  ≤  B[j]  ≤  C[k]. Note that i, j and k don’t exceed the size of respective arrays. For example, Arrays: A  =  [1, 2, 3, 4] B  =  [5, 6, 7, 8] C  =  [9, 10, 11, 12] The triplet (i, j, k)  =  (1, 2, 3) has to be considered because: A[1]  ≤  B[2]  ≤  C[3]. First line contains T, the number of test cases. Each test case consists of: P, the length of first array. The next line will consist of P integers. Q, the length of second array. The next line will consist of Q integers. R, the length of third array. The next line will consist of R integers. For each test case print the required answer in one line. *Constraints* The possible triplets (i, j, k) are: (1, 1, 1) (1, 1, 2) (1, 1, 3) (1, 2, 2) (1, 2, 3) (1, 3, 3) ## Input First line contains T, the number of test cases. Each test case consists of: P, the length of first array. The next line will consist of P integers. Q, the length of second array. The next line will consist of Q integers. R, the length of third array. The next line will consist of R integers. ## Output For each test case print the required answer in one line.*Constraints* 1  ≤  T  ≤  3 1  ≤  P, Q, R  ≤  105  - 109  ≤  Elements of arrays  ≤  109 [samples] ## Note The possible triplets (i, j, k) are: (1, 1, 1) (1, 1, 2) (1, 1, 3) (1, 2, 2) (1, 2, 3) (1, 3, 3)
**Definitions** Let $ T \in \mathbb{Z} $ be the number of test cases. For each test case: - Let $ P, Q, R \in \mathbb{Z}^+ $ denote the lengths of arrays $ A $, $ B $, and $ C $, respectively. - Let $ A = (a_1, a_2, \dots, a_P) $, $ B = (b_1, b_2, \dots, b_Q) $, $ C = (c_1, c_2, \dots, c_R) $ be three 1-indexed sorted arrays of integers. **Constraints** 1. $ T \geq 1 $ 2. For each test case: - $ 1 \leq P, Q, R \leq \text{some upper bound (implied by context)} $ - $ a_1 \leq a_2 \leq \dots \leq a_P $ - $ b_1 \leq b_2 \leq \dots \leq b_Q $ - $ c_1 \leq c_2 \leq \dots \leq c_R $ **Objective** Count the number of triplets $ (i, j, k) \in \{1, \dots, P\} \times \{1, \dots, Q\} \times \{1, \dots, R\} $ such that: $$ a_i \leq b_j \leq c_k $$
API Response (JSON)
{
  "problem": {
    "name": "J. Three Sorted Arrays",
    "description": {
      "content": "This time Laltu wanted the question to be straightforward. So, given 3 1-indexed sorted arrays (A[, B[], C[])], find the number of triplets 1  ≤  i  ≤  j  ≤  k, such that: A[i]  ≤  B[j]  ≤  C[k]. Note",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 524288
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10058J"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "This time Laltu wanted the question to be straightforward. So, given 3 1-indexed sorted arrays (A[, B[], C[])], find the number of triplets 1  ≤  i  ≤  j  ≤  k, such that: A[i]  ≤  B[j]  ≤  C[k]. Note...",
      "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:  \n- Let $ P, Q, R \\in \\mathbb{Z}^+ $ denote the lengths of arrays $ A $, $ B $, and $ C $, respectively.  ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments