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

Автор adaptatron, 6 месяцев назад, По-английски

The last Educational round contained an interesting problem D on Balanced parenthesis, which becomes almost trivial if someone has read this 8 year old comment by tenshi_kanade that talks about a much easier problem

Count the number of substrings that are balanced parenthesis.

I created a blog that talks about this idea in a bit more detail and also discusses how to modify the solution of this problem to make it work for the Edu problem. I also created practice problems on it so that you can submit your $$$O(n^2)$$$ and $$$O(n)$$$ approach. This is the contest link https://mirror.codeforces.com/group/7Dn3ObOpau/contest/527306

https://cfstep.com/training/tutorials/general-techniques/balanced-parenthesis-on-segments/

The problems are untested. If you see any issues, please let me know.

If you need any help or hints for the practice problem, you can ask on my Discord Server or on the Twitter thread. In case you are interested, you can also checkout my youtube channel

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

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

Nice solution ,but i was only able to follow upto O(n^2) due to segment tree.

  • »
    »
    6 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    No worries. Understanding the $$$O(n^2)$$$ algorithm is in fact the most difficult part of the blog.

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

Nice blog. Rest of the website seems useful too.

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

Using Segment Tree requires a lot of minor optimizations or else it gives TLE. Took me 4 submissions before I got AC :'-)

Time to add sparse table to my template...

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

    Not really. Atcoder library already provides a max_right function that does binary search inside the segment tree making the time complexity $$$O(n \cdot log(n))$$$. Easier than learning Sparse Table.

    Update : I also added code samples of how to use the max_right function in this context.