Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

Автор yshkpr, история, 5 лет назад, По-английски

Please help me to find why TLE is coming in my solution. Solution Link- https://atcoder.jp/contests/abc158/submissions/10968142

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

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

Your solution is brute, you are literally doing what the query asks you to do. In particular, lines $$$46$$$ and $$$47$$$ are too slow ( they are $$$O(|a|)$$$ which can be $$$O(N)$$$ ). So, the whole complexity becomes $$$O(Q*N)$$$.

You need to solve the problem, without updating the original string each time ( atleast I don't know a fast way to update the original string after each query ).