#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int n;
    cin >> n;
    int a[n], h;
    int help[31];
    help[0] = 1;
    for(int i = 1; i < 31;i++) {
        help[i] = help[i - 1]*2;
    }
    int howmuch[31] = {0}, reducer = 536870912;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        h = a[i];
        int o = upper_bound(help, help + 31, a[i]) - help;
        o--;
        reducer = help[o];
        while(h > 0) {
            if(reducer <= h){
                howmuch[o]+=1;
                h -= reducer;
            }
            reducer/=2;
            o--;
        }
    }

   // for(int i = 0; i < 31; i++) cout << howmuch[i] << " ";
   // cout << "\n";

   int q;
   cin >> q;
   for(int i = 0; i < q; i++) {
    int t, k;
    cin >> t >> k;
    if(t == 1) {
        int x;
        cin >> x;
        int gg = a[k - 1];
        int o = upper_bound(help, help + 31, gg) - help;
        o--;
        reducer = help[o];
        while(gg > 0) {
            if(reducer <= gg){
                howmuch[o]-=1;
                gg -= reducer;
            }
            reducer/=2;
            o--;
        }

        int gg2 = x;
        int o2 = upper_bound(help, help + 31, gg2) - help;
        o2--;
        reducer = help[o2];
        while(gg2 > 0) {
            if(reducer <= gg2){
                howmuch[o2]+=1;
                gg2 -= reducer;
            }
            reducer/=2;
            o2--;
        }
    }
    else {
            int rez = 0;
        for(int j = 0; j < 31; j++) {
            if(howmuch[j] >= k){
                rez += help[j];
            }
        }
        cout << rez << "\n";
    }
   }
    return 0;
}