fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int MAX = 5e5 + 5;
  6.  
  7. int n, q;
  8. int s[MAX];
  9. int a[MAX];
  10. int main() {
  11. ios_base::sync_with_stdio(false);
  12. cin.tie(NULL);
  13.  
  14. cin >> n >> q;
  15.  
  16. for (int i = 1; i <= n; i++)
  17. {
  18. char x; cin >> x;
  19. a[i] = x - 'A';
  20. if (i > 1) s[i] = s[i-1] + (a[i] == a[i-1]);
  21. }
  22.  
  23. while(q--)
  24. {
  25. int l, r; cin >> l >> r;
  26. cout << s[r] - s[l] << "\n";
  27. }
  28.  
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0.01s 5296KB
stdin
7 4
BBRBBRR
1 7
1 5
3 7
4 5
stdout
3
2
2
1