G. Strange Queries

Codeforces
IDCF10286G
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
You are given $n$ strings, and you need to answer $q$ queries. Each query is composed of two strings $l_i$ and $r_i$. For such a query, you need to count the number of the given strings such that either it has $l_i$ as a prefix, $r_i$ as a suffix, or both (thus, a string that has $l_i$ for a prefix and $r_i$ for a suffix should be counted once). The first line contains a single integer $n$ ($1 <= n <= 10^5$), the number of strings. Then follow $n$ strings, each in its own line. The next line contains a single integer $q$ ($1 <= q <= 10^5$), the number of queries. Then $q$ lines follow, the $i$-th of them contains two strings $l_i$ and $r_i$. None of the strings in the input is empty. The sum of the lengths of all strings in the input does not exceed $10^5$ (including queries). All strings consist of lowercase English alphabet letters only. For each query, output the number of the given strings that have either the given prefix or the given suffix (or both). ## Input The first line contains a single integer $n$ ($1 <= n <= 10^5$), the number of strings. Then follow $n$ strings, each in its own line. The next line contains a single integer $q$ ($1 <= q <= 10^5$), the number of queries. Then $q$ lines follow, the $i$-th of them contains two strings $l_i$ and $r_i$. None of the strings in the input is empty.The sum of the lengths of all strings in the input does not exceed $10^5$ (including queries). All strings consist of lowercase English alphabet letters only. ## Output For each query, output the number of the given strings that have either the given prefix or the given suffix (or both). [samples]
**Definitions** Let $\phi(x)$ denote the function that maps a positive integer $x$ to the integer formed by replacing each digit $d$ in $x$ with $9 - d$, then removing leading zeros. Let $f(x) = x \cdot \phi(x)$ be the id code function. **Given** Let $t \in \mathbb{Z}$ be the number of test cases, with $1 \le t \le 1000$. For each test case $i \in \{1, \dots, t\}$, we are given an interval $[l_i, r_i]$ with $1 \le l_i \le r_i \le 10^9$. **Objective** For each interval $[l_i, r_i]$, compute: $$ \max_{x \in [l_i, r_i] \cap \mathbb{Z}} f(x) = \max_{x \in [l_i, r_i] \cap \mathbb{Z}} \left( x \cdot \phi(x) \right) $$
API Response (JSON)
{
  "problem": {
    "name": "G. Strange Queries",
    "description": {
      "content": "You are given $n$ strings, and you need to answer $q$ queries. Each query is composed of two strings $l_i$ and $r_i$. For such a query, you need to count the number of the given strings such that eith",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10286G"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given $n$ strings, and you need to answer $q$ queries. Each query is composed of two strings $l_i$ and $r_i$. For such a query, you need to count the number of the given strings such that eith...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $\\phi(x)$ denote the function that maps a positive integer $x$ to the integer formed by replacing each digit $d$ in $x$ with $9 - d$, then removing leading zeros.  \n\nLet $f(x) = ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments