AT_abc465_f.Sjeltzer?

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

This refrigerator stores NN drinks. The ii-th drink has ID SiS_i and size ViV_i. S1,…,SNS_1, \dots, S_N are distinct.

Answer QQ queries. Each query is given in the form of 66-digit numeric strings x,yx, y, and asks the following.

  • Among the drinks stored in this refrigerator, find the sum of the sizes of those whose assigned ID ss satisfies the following for every k=1,…,6k = 1, \dots, 6.
    • xk≤sk≤ykx_k \leq s_k \leq y_k, where sk,xk,yks_k, x_k, y_k denote the values represented by the kk-th digits of s,x,ys, x, y, respectively.

某台冰箱为每瓶饮料分配一个 66 位数字字符串作为其 ID。

该冰箱共存储 NN 瓶饮料。第 ii 瓶饮料的 ID 为 SiS_i,体积为 ViV_i。S1,…,SNS_1, \dots, S_N 互不相同。

回答 QQ 个查询。每个查询给出两个 66 位数字字符串 xx 和 yy,要求如下:

  • 在该冰箱所存储的饮料中,找出所有满足如下条件的饮料,并求它们的体积之和:
    • 对于每个 k=1,…,6k = 1, \dots, 6,均有 xk≤sk≤ykx_k \leq s_k \leq y_k,其中 sk,xk,yks_k, x_k, y_k 分别表示字符串 s,x,ys, x, y 的第 kk 位数字所代表的数值。

输入格式

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

NN
S1S_1 V1V_1
…\dots
SNS_N VNV_N
QQ
query1\mathrm{query}_1
⋮\vdots
queryQ\mathrm{query}_Q

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

xx yy

输入从标准输入给出,格式如下:

NN
S1S_1 V1V_1
…\dots
SNS_N VNV_N
QQ
query1\mathrm{query}_1
⋮\vdots
queryQ\mathrm{query}_Q

其中,queryq\mathrm{query}_q 表示第 qq 个查询,其格式如下:

xx yy

输出格式

Output QQ lines. The qq-th line should contain the answer to the qq-th query.

输出 QQ 行。第 qq 行应包含第 qq 个查询的答案。

输入输出样例

  • 输入#1

    5
    000000 1
    314159 2
    161803 10
    169231 5
    384400 20
    4
    150001 269944
    302010 396939
    000000 999999
    999000 000444

    输出#1

    15
    0
    38
    0
  • 输入#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

    输出#2

    515024780
    109900930
    0
    331175626
    331175626
    331175626
    584885376
    331175626

说明/提示

Sample 1 Explanation:
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.

Constraints

  • NN is an integer.
  • 1≤N≤3×1051 \leq N \leq 3 \times 10^5
  • SiS_i is a string consisting of digits (0-9).
  • ∣Si∣=6|S_i| = 6
  • S1,…,SNS_1, \dots, S_N are distinct.
  • ViV_i is an integer.
  • 1≤Vi≤1091 \leq V_i \leq 10^9
  • QQ is an integer.
  • 1≤Q≤3×1051 \leq Q \leq 3 \times 10^5
  • In each query, xx and yy are strings consisting of digits (0-9).
  • In each query, ∣x∣=∣y∣=6|x| = |y| = 6.

样例 1 解释:
对于第一个查询,满足条件的饮品是第三种和第四种饮品。

对于第二个查询,没有饮品满足条件。

对于第三个查询,满足条件的饮品是第一种、第二种、第三种、第四种和第五种饮品。

对于第四个查询,没有饮品满足条件。

约束条件

  • NN 是一个整数。
  • 1≤N≤3×1051 \leq N \leq 3 \times 10^5
  • SiS_i 是一个仅由数字(0–9)组成的字符串。
  • ∣Si∣=6|S_i| = 6
  • S1,…,SNS_1, \dots, S_N 互不相同。
  • ViV_i 是一个整数。
  • 1≤Vi≤1091 \leq V_i \leq 10^9
  • QQ 是一个整数。
  • 1≤Q≤3×1051 \leq Q \leq 3 \times 10^5
  • 在每次查询中,xx 和 yy 均为仅由数字(0–9)组成的字符串。
  • 在每次查询中,∣x∣=∣y∣=6|x| = |y| = 6

输入解题思路,AI测评打分。不知道怎么写?

首页