prabalsingh24's blog

By prabalsingh24, history, 5 years ago, In English

This is the problem https://codeforces.net/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?

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
5 years ago, # |
  Vote: I like it +4 Vote: I do not like it

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