M. The business man

Codeforces
IDCF10199M
Time5000ms
Memory1024MB
Difficulty
English · Original
Formal · Original
Badry is tired of programming, that is why he wanted to try his chances in business world. Badry opened a company that trades in antiques. The company owns $N$ different shops where the $i_{t h}$ shop has its location $X_i$ on the $O X$ axis and its product has initial quality $Q_i$. Moreover, there are two more strange facts about these shops: Currently, Badry has $M$ orders from $M$ different customers where the $i_{t h}$ customer is located at position $Y_i$ and requesting his product to be with quality at least $D_i$. Can you help Badry by determining the number of shops that can serve each customer ? You can assume that each shop has infinite number of products. The first line of input contains the number of test cases $T$. Each test case starts with a line containing two integers $N$ and $M$ the number of shops and the number of customers respectively, where $1 <= N, M <= 10^5$. Each of the next $N$ lines contains three integers $X_i$, $Q_i$ and $R_i$ representing the $i_{t h}$ shop, where $1 <= X_i, Q_i, R_i <= 10^9$. Each of the following $M$ lines contains two integers $Y_i$ and $D_i$ representing the $i_{t h}$ customer, where $1 <= Y_i, D_i <= 10^9$. All the positions of the shops are given in a non-decreasing order. Also all positions of the customers are given in a non-decreasing order. For each test case output a single line containing $M$ space-separated integers, the number of possible serving shops for each customer. Please output the answer for customers in the same order they appeared in input. ## Input The first line of input contains the number of test cases $T$. Each test case starts with a line containing two integers $N$ and $M$ the number of shops and the number of customers respectively, where $1 <= N, M <= 10^5$. Each of the next $N$ lines contains three integers $X_i$, $Q_i$ and $R_i$ representing the $i_{t h}$ shop, where $1 <= X_i, Q_i, R_i <= 10^9$.Each of the following $M$ lines contains two integers $Y_i$ and $D_i$ representing the $i_{t h}$ customer, where $1 <= Y_i, D_i <= 10^9$. All the positions of the shops are given in a non-decreasing order. Also all positions of the customers are given in a non-decreasing order. ## Output For each test case output a single line containing $M$ space-separated integers, the number of possible serving shops for each customer. Please output the answer for customers in the same order they appeared in input. [samples]
**Definitions** Let $ T \in \mathbb{Z} $ be the number of test cases. For each test case: - Let $ N, M \in \mathbb{Z} $ denote the number of shops and customers, respectively. - Let $ S = \{(x_i, q_i, r_i) \mid i \in \{1, \dots, N\}\} $ be the set of shops, where: - $ x_i \in \mathbb{R} $ is the position on the $OX$ axis, - $ q_i \in \mathbb{Z}^+ $ is the initial quality, - $ r_i \in \mathbb{Z}^+ $ is the range (radius) of the shop. - Let $ C = \{(y_j, d_j) \mid j \in \{1, \dots, M\}\} $ be the set of customers, where: - $ y_j \in \mathbb{R} $ is the customer’s position, - $ d_j \in \mathbb{Z}^+ $ is the minimum required quality. **Constraints** 1. $ 1 \le T \le \text{unknown} $ (implied by input format) 2. $ 1 \le N, M \le 10^5 $ 3. $ 1 \le x_i, q_i, r_i, y_j, d_j \le 10^9 $ 4. The sequence $ (x_1, x_2, \dots, x_N) $ is non-decreasing. 5. The sequence $ (y_1, y_2, \dots, y_M) $ is non-decreasing. **Objective** For each customer $ j \in \{1, \dots, M\} $, compute: $$ c_j = \left| \left\{ i \in \{1, \dots, N\} \ \middle| \ |x_i - y_j| \le r_i \ \land \ q_i \ge d_j \right\} \right| $$ Output $ c_1, c_2, \dots, c_M $ for each test case.
API Response (JSON)
{
  "problem": {
    "name": "M. The business man",
    "description": {
      "content": "Badry is tired of programming, that is why he wanted to try his chances in business world. Badry opened a company that trades in antiques. The company owns $N$ different shops where the $i_{t h}$ shop",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 5000,
      "memory_limit": 1048576
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10199M"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Badry is tired of programming, that is why he wanted to try his chances in business world. Badry opened a company that trades in antiques. The company owns $N$ different shops where the $i_{t h}$ shop...",
      "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 $ N, M \\in \\mathbb{Z} $ denote the number of shops and customers, respectively.  \n- Let $ S = \\{(x...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments