#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 = max(pos[mid] - k, mid);
(final < x ? l : r) = mid;
}
// if (r<m) cout << x << " " << r << " " << pos[r] << " after " << k << " rounds: " << max(pos[r] - k, r) << "\n";
return r;
};
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";
}
}
}