This approach is in O(n) i tried to find better approcah // https://www.geeksforgeeks.org/find-the-occurrences-of-y-in-the-range-of-x/
but I cannt find any approch please suggest me..
This approach is in O(n) i tried to find better approcah // https://www.geeksforgeeks.org/find-the-occurrences-of-y-in-the-range-of-x/
but I cannt find any approch please suggest me..
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3676 |
| 2 | jiangly | 3670 |
| 3 | Kevin114514 | 3657 |
| 4 | maroonrk | 3355 |
| 5 | Um_nik | 3353 |
| 6 | squareOf105 | 3346 |
| 7 | tourist | 3343 |
| 8 | strapple | 3324 |
| 9 | heuristica | 3322 |
| 10 | jiangbowen | 3291 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 158 |
| 2 | nik_exists | 150 |
| 2 | maspy | 150 |
| 4 | AmShZ | 143 |
| 5 | Um_nik | 141 |
| 6 | Errichto | 139 |
| 7 | adamant | 137 |
| 8 | BledDest | 134 |
| 9 | maroonrk | 133 |
| 10 | qwexd | 130 |
| Name |
|---|



Let $$$f_{x,y}$$$ be the quantity of digits $$$y$$$ among numbers $$$[0, x]$$$.
Then to answer the query $$$l, r, d$$$ is simply $$$f_{r,d} - f_{l-1,d}$$$.
Preprocissing is $$$O(n * log_{10}n)$$$, and each query if $$$O(1)$$$.
So the total complexity is $$$O(n * log_{10}n + q)$$$.
By the way, I think there's a more efficient way to solve this problem:
at first read https://codeforces.me/blog/entry/77096 if you aren't familiar with digit dp.
After this we have a $$$dp_{i,j,flag} - $$$ quantity of numbers of length $$$i$$$ with $$$j$$$ digits $$$x$$$, and flag tells us whether our prefix of length $$$i$$$ is equal to prefix of length $$$i$$$ of number $$$n$$$ (you can read about it more in the blog I mentioned above).
Time complexity is $$$O(log_{10}n)$$$
Lets all digits we have to check is in range $$$[head, tail]$$$ where $$$head$$$ can simply be $$$0$$$ (first index of vector, array, etc in C++)
Lets
magic(int pos, bool isLess, int cnt)is the current number with digits range $$$(head, pos)$$$ are build and the part $$$(head, pos)$$$ is currently less than digits range $$$(head, pos)$$$ of $$$n$$$ if ($$$isLess$$$ true) which $$$cnt$$$ digits $$$x$$$If $$$isLess$$$ is true then we can chose what ever digit in range $$$[0, 9]$$$ we want since the number we selecting is already smaller than $$$n$$$
If $$$isLess$$$ is false then we can only chose digit that not greater than $$$n[pos]$$$ which is in range $$$[0, n[pos]]$$$
If selected digit is $$$x$$$ then we increase the counter for next recursive by one
If selected digit is smaller than $$$n[digit]$$$ then $$$isLess$$$ of the next recursive will be true
If current selected digit is in position $$$tail$$$, then we return $$$cnt$$$, which is the number of digit $$$x$$$ appear in the number we built so far
Then after all, we just need to add memorization of 3 dimentional: $$$f[pos][isLess][cnt]$$$. If it is calculated than we just need to return the value, else keep calculating and update current dp function $$$f[][][]$$$