#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define popcount __builtin_popcount
#define all(a) (a).begin(), (a).end()
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
template<typename T> using ordered_set = tree<T,null_type,less_equal<>,rb_tree_tag,tree_order_statistics_node_update>;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q; cin >> n;
vector<int> pos;
for (int i = 0, x; i < n; i++) {
cin >> x;
if (x == 1) pos.push_back(i);
}
int m = pos.size(), k = 0;
auto leftmost = [&](int x) {
// int l = -1, r = m;
// while (r-l > 1) {
// int mid = (l+r)/2;
// int final = min(pos[mid] + k, n - m + mid);
// (x <= final ? r : l) = mid;
// }
int res = 0;
for (int p = 0; p < m; p++) {
int final = max(pos[p] - k, p);
res += final < x;
}
return res;
};
cin >> q; while (q--) {
int t, l, r; cin >> t;
if (t == 1) k++;
else {
cin >> l >> r;
l--;
cout << 2*(r-l) - (leftmost(r) - leftmost(l)) << "\n";
}
}
}