Source Code
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <map>
#define ll long long
#define endl '\n'
#define Pi 3.1415926535898
const int N = 2e6 + 5;
#define watch(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(),(v).end()
using namespace std;
// cout << fixed << setprecision(9);
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
}
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 }; // dir array
int dy[] = { 1, -1, 0, 0, 1, -1, -1, 1 };

int main() {
	fast();
	file();
	//bitset<32> bits("01110101");
	// cout << bits.to_ulong() << endl;
	string s; 
	cin >> s; 
	int sz = s.size(); 
	vector <int> v(sz + 1); 
	v[0] = 0;
	for (int i = 0;i < sz;i++) {
		if (s[i] == '0') {
			v[i+1] = (v[i] * 2) % 10 ; 
		}
		else {
			v[i+1] = ((v[i] * 2) % 10) +1 ; 
		}
	}
	//for (auto it : v) cout << it << " "; 
	int q; 
	cin >> q; 
	while (q--) {
		int l, r; 
		cin >> l >> r; 
		cout << v[r] << endl;
	}
	return 0;
}
Copy
Binarithm Marah Mohamed
GNU G++17
74 ms
1.8 MB
Wrong Answer