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 = 6e18;
const auto EPS = 1e-6;
const auto PI = acos(-1);
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 };

ll fpow(ll x, ll n)
{
	ll res = 1;
	while(n)
	{
		if(n&1LL)
		{
			res *= x;
		}
		n >>= 1LL;
		x *= x;
	}
	return res;
}
void testCase()
{
	string s;
	cin  >> s;
	ll q;	
	cin >> q;
	while(q--)
	{
		ll l, r;
		cin >> l >> r;
		ll res = 0;
		for(int i=0;i<60;i++)
		{
			if(s[r-1-i]-'0')
				res += fpow(2, i);
			if(r-1-i == 0 || r-1-i == l-1)
				break;
		}
		cout << res %10 << '\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
278 ms
992 KB
Wrong Answer