Skip to content

Instantly share code, notes, and snippets.

@jo32
Created October 14, 2015 03:11
Show Gist options
  • Select an option

  • Save jo32/2355645469423a7b1885 to your computer and use it in GitHub Desktop.

Select an option

Save jo32/2355645469423a7b1885 to your computer and use it in GitHub Desktop.
CODEFORCE 313B
import bisect
s = raw_input()
nCases = int(raw_input())
cases = [[int(i) for i in raw_input().split(' ')] for x in range(nCases)]
dp = [0] * (len(s) + 1)
for i in range(1, len(s)):
dp[i] = dp[i - 1] + 1 if s[i - 1] == s[i] else dp[i - 1]
for [l, r] in cases:
amount = dp[r - 1] - dp[l - 1]
print amount
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment