累積和とるだけ

B. Ilya and Queries

#include <iostream>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
using namespace std;
int main() {
    string s; cin >> s;
    int n = s.length();
    vector<int> a(n+1);
    repeat (i,n) a[i+1] = a[i] + (s[i] == s[i+1]);
    int m; cin >> m;
    repeat (i,m) {
        int l, r; cin >> l >> r;
        -- l; -- r;
        cout << a[r] - a[l] << endl;
    }
    return 0;
}