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

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

This is the problem https://mirror.codeforces.com/contest/1234/problem/D I made segment tree for each alphabet (26) and calculated sum of segments. So if the query is to find distinct character in [l,r] I find sum in [l,r] in each of the 26 segment tree and answer is number of non zero segments. https://ide.codingblocks.com/s/137727 This solution is giving WA in test case#2. However when i swap the line 91 and 92. I get AC. https://ide.codingblocks.com/s/137726 The line 91 and 92 are only the update statement and they are not related to each other. If the query is to change the character in 'pos' index to 'ch', I add 1 to 'pos' index in ch segment tree and change the index at old character segment tree to 0. Why is this happening?

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

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

Auto comment: topic has been updated by prabalsingh24 (previous revision, new revision, compare).

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

The problem comes when both prev and cur are the same character, that is why you need to remove it first and then add the character