"Mo Team" bzoj4542: [Hnoi2016] Large number

Source: Internet
Author: User

Very interesting, you can carefully appreciate the problem, see White is Mo Team board.

Description

Small B has a large number of S, the length reached N bits; This number can be seen as a string, it may have a leading 0, for example 00009312345
。 Small B also has a prime number p. Now, small B raises M queries, and each query asks how many substrings in a substring of S are multiples of P (0 Also
is a multiple of P). For example, S is 0077, its substring 007 has 6 substrings: 0,0,7,00,07,007; obviously 0077 of the substring 007 has 6 substrings are all vegetarian
Multiples of 7.

Input

The first line is an integer: P. The second line is a string: S. The third line is an integer: M. The next m line, two integers per line fr,to, represents the
Sub-string s[fr...to]. Note: The leftmost number of S has a position ordinal of 1; For example, S is 213567, then s[1] is 2,s[1 ... 3] is 2
13. N,m<=100000,p as prime number

Output

Output m lines, one integer per line, and line I is the answer to the I query.

Problem analysis

An interval [l,r] produces a contribution that is _{i,j}\equiv 0\ ({\rm mod}\ p) $.

according to common routines, the interval should be split into a formula about the endpoint. Use $pre[i]$ to represent the value of the former $i$ bit in decimal, then _{i,j}=pre[j]-10^{j-i+1}*pre[i-1]$

"Mo Team" bzoj4542: [Hnoi2016] Large number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.