SORTOUT - Mahammad and strings
Professor Mahammad was busy with working their machine learning project in XYZ University. His team collected many data for the analysis of specific procedures. As the length of individual data objects were quite large, he used a popular hashing technique for getting a unique identifier for each data. Unfortunately, the hashing function generated similar result strings for data. As it is not suitable for the project, he started to think what to do with those strings. Suddenly, he came up with a new idea for a problem for beginners. Now he asks, for the given strings in each query, how many lexicographically smaller or equal strings exist in the input?
Input
First line of the input contains two positive integers N and Q, respectively, the number of input strings and the number of queries.
The following N lines represent the strings generated from the procedure.
Finally, the next Q lines contain the query strings which you need to process.
The input section contains strings with only lowercase English letters.
Output
For each of the Q lines, you need to output the number of equal or lexicographically smaller strings.
Note: The sum of the lengths of the input and query strings does not exceed 200000, separately.
Example
Input: 4 3 fury fuzzy dizzy future fuzz evil freeze Output: 3 1 1
hide comments
vineetjai:
2020-09-05 10:12:29
Use "\n" instead of endl. Expected Complexity: O(nlogn+q*logn) |
|
hodobox:
2018-12-31 04:02:15
I agree with wisfaq. A O(n^2) or O(nq)-ish solution won't run in a fast language (C++) even in 5s if the cases are strong, so the only way to get AC even with a 1s limit would be with a correct algorithm anyway. Like this, it's just turning down solvers for no reason - not preventing any excess 'bad solutions', just TLE'ing correct ideas in a slow language/with a small constant.
|
|
julkas:
2017-09-30 14:53:21
I think time limit is OK. You must find the best algo. Good problem. |
|
[Rampage] Blue.Mary:
2017-09-30 11:45:44
If the constraints are set to "The total length of input string doesn't exceed 5000000" and "time limit is 3 seconds", we may not waste so much time quarrel with each other. |
|
wisfaq:
2017-09-30 10:15:23
No need to change the time limit if the problem is moved to tutorial
|
|
Min_25:
2017-09-30 04:54:46
"The sum of the lengths of the input and query strings does not exceed 200000" is not correct.
|
|
[Rampage] Blue.Mary:
2017-09-30 01:21:57
It seems that Java is too slow for this problem. Nevertheless, I don't think the time limit should be changed, because not all problems are designed to be solved in any programming language.
|
|
wisfaq:
2017-09-29 20:54:16
I don't think your answer is a proper reply to my post.
|
|
wisfaq:
2017-09-29 10:10:17
Some languages have a rather long start up time on SPOJ (e.g. Java and Pypy).
|
|
testing java:
2017-09-29 00:10:20
Was there some huge performance upgrade between g++ 4.3.2 and gcc 6.3? i tried sending exactly same code using different compilers and gcc 6.3 results with AC and g++ 4.3.2 with TLE.
|
Added by: | mahmud2690 |
Date: | 2017-09-25 |
Time limit: | 0.100s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | Me, MYSELF & I |