Блог пользователя dunjen_master

Автор dunjen_master, история, 4 года назад, По-английски

I am attaching a picture about the question. Kindly refer to the picture.

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Sample test cases?

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

You didn't tell us whether the test is finished or not. We shouldn't help you if the test is not finished yet.

»
4 года назад, # |
Rev. 4   Проголосовать: нравится +3 Проголосовать: не нравится

Reverse all strings, so task becomes about prefix instead of suffix. Create segment tree, where each node have a trie that contains all strings from this node's corresponding segment (each string will be in $$$log~n$$$ tries, so memory will be $$$23 \cdot n~log~n$$$). With trie it's easy to count necessary sum of all string nested in this trie in $$$O(23)$$$, so overall query's complexity will be $$$O(23 \cdot log~n)$$$.

»
4 года назад, # |
  Проголосовать: нравится +12 Проголосовать: не нравится

create a trie with reversed strings and store indices of strings in each node in sorted order then query for reversed string, you can find out for each each prefix of reversed string how many strings from given range match this prefix

  • »
    »
    4 года назад, # ^ |
    Rev. 2   Проголосовать: нравится +6 Проголосовать: не нравится

    For updates you will need to store indices in BSTs that supports query "how many elements is smaller than given value". But that a nice alternative to segment tree's solution and it even has lower memory consumption complexity.

»
4 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

I solved it using map and policy based data structure My solution