AtCoder Beginner Contest 465
F
Sjeltzer?
Sjeltzer?
AtCoder
⌀ 1754
原题
←G →

Sjeltzer?AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

A certain refrigerator assigns each drink a $6$-digit numeric string as its ID.

某冰箱会为每种饮料分配一个 $6$ 位数字字符串作为其 ID。AI (CI翻译)

This refrigerator stores $N$ drinks. The $i$-th drink has ID $S_i$ and size $V_i$. $S_1, \dots, S_N$ are distinct.

该冰箱中存放着 $N$ 种饮料。第 $i$ 种饮料的 ID 为 $S_i$,大小为 $V_i$。$S_1, \dots, S_N$ 互不相同。AI (CI翻译)

Answer $Q$ queries. Each query is given in the form of $6$-digit numeric strings $x, y$, and asks the following.

请回答 $Q$ 个询问。每个询问给出两个 $6$ 位数字字符串 $x, y$,询问如下内容。AI (CI翻译)

  • Among the drinks stored in this refrigerator, find the sum of the sizes of those whose assigned ID $s$ satisfies the following for every $k = 1, \dots, 6$.
  • $x_k \leq s_k \leq y_k$, where $s_k, x_k, y_k$ denote the values represented by the $k$-th digits of $s, x, y$, respectively.
  • 在该冰箱存放的饮料中,求其分配的 ID $s$ 对于所有 $k = 1, \dots, 6$ 都满足以下条件的饮料的大小之和。
  • $x_k \leq s_k \leq y_k$,其中 $s_k, x_k, y_k$ 分别表示 $s, x, y$ 的第 $k$ 位数字所代表的数值。
AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $N$ is an integer.
  • $1 \leq N \leq 3 \times 10^5$
  • $S_i$ is a string consisting of digits (0-9).
  • $|S_i| = 6$
  • $S_1, \dots, S_N$ are distinct.
  • $V_i$ is an integer.
  • $1 \leq V_i \leq 10^9$
  • $Q$ is an integer.
  • $1 \leq Q \leq 3 \times 10^5$
  • In each query, $x$ and $y$ are strings consisting of digits (0-9).
  • In each query, $|x| = |y| = 6$.
  • $N$ 是整数。
  • $1 \leq N \leq 3 \times 10^5$
  • $S_i$ 是由数字(0-9)组成的字符串。
  • $|S_i| = 6$
  • $S_1, \dots, S_N$ 互不相同。
  • $V_i$ 是整数。
  • $1 \leq V_i \leq 10^9$
  • $Q$ 是整数。
  • $1 \leq Q \leq 3 \times 10^5$
  • 每个询问中的 $x$ 和 $y$ 都是由数字(0-9)组成的字符串。
  • 每个询问中,$|x| = |y| = 6$。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format:

输入从标准输入给出,格式如下:AI (CI翻译)

N
S_1 V_1
\dots
S_N V_N
Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q

N
S_1 V_1
\dots
S_N V_N
Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q
AI (CI翻译)

Here, $\mathrm{query}_q$ is the $q$-th query, given in the following format:

其中,$\mathrm{query}_q$ 表示第 $q$ 个询问,其格式如下:AI (CI翻译)

x y

x y
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output $Q$ lines. The $q$-th line should contain the answer to the $q$-th query.

输出 $Q$ 行。第 $q$ 行应包含第 $q$ 个询问的答案。AI (CI翻译)

样例

Input #1
5
000000 1
314159 2
161803 10
169231 5
384400 20
4
150001 269944
302010 396939
000000 999999
999000 000444
Output #1
15
0
38
0
For the first query, the drinks satisfying the condition are the third and fourth drinks. For the second query, no drinks satisfy the condition. For the third query, the drinks satisfying the condition are the first, second, third, fourth, and fifth drinks. For the fourth query, no drinks satisfy the condition.
Input #2
8
778722 12744734
488742 359266786
955942 335004463
454854 331175626
934246 179761526
927777 657312747
652568 109900930
753279 405123850
8
201000 785589
202325 955898
310401 875947
044023 988999
111230 567897
133241 577989
101033 999499
453013 796988
Output #2
515024780
109900930
0
331175626
331175626
331175626
584885376
331175626
题目信息
题号
abc465_f
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。