QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 64 MB Total points: 10

#10663. Fragments [A]

الإحصائيات

We are given a set $ A $ of positive integers. For a given sequence of digits $ x $, we would like to know how many times it occurs, as a fragment (i.e., a contiguous part), in the numbers from the set $ A $. Note that a sequence $ x $ may occur as a fragment of a given $ a $ ∈ $ A $ multiple times - then we are interested in all its occurrences.

Input Format

The first line of the standard input contains two integers $ n $ and $ m $ (1 ≤ $ n $ ≤ 5 000, 1 ≤ $ m $ ≤ 500 000) representing the number of lines containing a description of the set $ A $ and the number of sequences of digits denoting the queries. Each of the following $ n $ lines contains two integers $ a_{i} $ and $ b_{i} $. These numbers satisfy the following inequalities: 1 ≤ $ a $_{1} ≤ $ b $_{1} < $ a $_{2} ≤ $ b $_{2} < $ a $_{3} ≤ $ b $_{3} < ... < $ a_{n} $ ≤ $ b_{n} $ ≤ 10^{18} and represent the following set: $ A $ = [$ a $_{1},$ b $_{1}] ∪ [$ a $_{2},$ b $_{2}] ∪ [$ a $_{3},$ b $_{3}] ∪ ... ∪ [$ a_{n} $,$ b_{n} $].

Each of the following $ m $ lines contains a sequence of digits $ x_{j} $ consisting of at least 1 and at most 19 digits 0..9.

Output Format

Your program should write $ m $ lines to the standard output. The $ i $-th of these lines should contain a single integer: the total number of occurrences of $ x_{j} $ in all numbers from the set $ A $, including multiple occurrences in respective elements of $ A $.

Example

Input

1 3
2220 2223
222
0
07

Output

5
1
0
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.