Getting two tle in question :"SIMPLE ENOUGH"

question link: https://hack.codingblocks.com/contests/c/547/907
i am not able to guess how to solve this question,any hint will be appreciated.

unoptimised solution:https://ide.codingblocks.com/s/43462

This problem is somewhat similar to binary_search or divide and conquer, or you may think this in terms of query part of segment trees. Basically, you have to use divide and conquer. Think of some recursion to solve it.

Let me help you understand the sample case.

9 6 9

  1. Count the number of characters in the final answer. This is easy using recursion.
  2. So you have a string from index 1 to index 15.
  3. mid=(15+1)/2 = 8.
  4. Is 8 between L and R. Yes. This means that character at this point needs to be counted. Now what is the 8th character. Characters 1-7 belong to floor of N/2. Characters 9-15 belong to floor of N/2. And character 8 is for N%2.
  5. Let the recursion solve from index 1 to 7 and for index 9 to 15.
  6. Be careful with the base cases.

https://ide.codingblocks.com/s/43530

This is my solution. Avoid looking at it because this will spoil the fun of this amazing problem.
Keep coding…!!