Source Code
#include <bits/stdc++.h>
#define ld long double
#define ll long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(s)    (int)(s.size())
const ll N = 2e5+3, mod = 1000000007;
const ll OO = 1e18;
const auto EPS = 1e-6;
using namespace std;
int DX[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int DY[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dx[] = { 1,0,-1,0 } ,dy[] = { 0,1,0,-1 };

int pre[200001];
void testCase()
{
  string s;
  cin >> s;
  int n = s.length();
  for(int i=1;i<=s.length();i++)
  {
    pre[i] = (pre[i-1]*2 + (s[i-1] == '1'))%10;
  }
  int q;
  cin >> q;
  while(q--)
  {
    int l, r;
    cin >> l >> r;
    cout << (pre[r] ^ (pre[l]/2)) << '\n';
  }
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;  //cin >> t;
  for(int tc = 1;tc<=t;tc++)
  {
    // cout << "Case #" << tc << ": ";
      testCase();
  }
  return 0;
}
Copy
Binarithm MuhammedKhedr
GNU G++17
94 ms
1.7 MB
Wrong Answer