intread() { int x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - '0', c = getchar(); return x * f; } intqpow(int a, int x, int mo) { int res = 1; while (x) { if (x & 1) res = 1ll * res * a % mo; x >>= 1; a = 1ll * a * a % mo; } return res; } intinc(int x, int y, int mo) { if (y < 0) y += mo; if (x + y >= mo) x -= mo; return x + y; }
constint SEN = 4e5 + 10; structsegmentTree { int sum[SEN << 2], lazy[SEN << 2]; voidaddtag(int pos, int l, int r, int w) { lazy[pos] += w; sum[pos] += w * (r - l + 1); } voidpushdown(int pos, int l, int r) { if (lazy[pos]) { int w = lazy[pos]; int mid = (l + r) >> 1; addtag(pos << 1, l, mid, w); addtag(pos << 1 | 1, mid + 1, r, w); lazy[pos] = 0; } } voidpushup(int pos) { sum[pos] = sum[pos << 1 | 1] + sum[pos << 1]; } intquery(int ql, int qr, int pos, int l, int r) { if (ql <= l && r <= qr) { return sum[pos]; } pushdown(pos, l, r); int mid = (l + r) >> 1; int ans = 0; if (ql <= mid) ans += query(ql, qr, pos << 1, l, mid); if (qr > mid) ans += query(ql, qr, pos << 1 | 1, mid + 1, r); return ans; } voidupdate(int ql, int qr, int w, int pos, int l, int r) { if (ql <= l && r <= qr) { addtag(pos, l, r, w); return; } pushdown(pos, l, r); int mid = (l + r) >> 1;
if (ql <= mid) update(ql, qr, w, pos << 1, l, mid); if (qr > mid) update(ql, qr, w, pos << 1 | 1, mid + 1, r); pushup(pos); } } T; int Inv2; voidFWT(int *A, int n, int op, int t)//t=1 or t=2 and t=3 xor { for (int i = 2; i <= n; i <<= 1) { for (int j = 0, mid = i >> 1; j < n; j += i) for (int k = 0; k < mid; k++) {
for (int i = 0; i < n; ++i) A[i] = 1ll * A[i] * B[i] % mod; FWT(A, n, -1, t); }
int f[N], g[N]; structnode { ll l, r; } q[N]; ll li[N]; int a[N]; ll sum[N]; int cnt = 0; intmain() { int n = read();
for (int i = 1; i <= n; i++) { int x = read(); f[x]++; } for (int i = 1; i <= n; i++) { int x = read(); g[x]++; } FWTX(f, g, 1 << 17, 1); sum[0] = f[0]; for (int i = 1; i < (1 << 17); i++) {
sum[i] = sum[i - 1] + f[i]; }
int m = read(); for (int i = 1; i <= m; i++) { q[i].l = read(), q[i].r = read(); if (q[i].l != 0) li[++cnt] = (q[i].l); li[++cnt] = (q[i].r); } sort(1 + li, 1 + li + cnt); cnt = unique(li + 1, li + 1 + cnt) - li - 1; for (int i = 1; i <= m; i++) { if (q[i].l == 0) { int r = lower_bound(1 + li, 1 + li + cnt, q[i].r) - li; a[r] = lower_bound(sum, sum + (1 << 17), q[i].r) - sum; q[i].r = r; } else { q[i].l = lower_bound(1 + li, 1 + li + cnt, q[i].l) - li; q[i].r = lower_bound(1 + li, 1 + li + cnt, q[i].r) - li; } } for (int i = 1; i <= m; i++) { if (q[i].l == 0) { int p = T.query(q[i].r, q[i].r, 1, 1, cnt); int res = a[q[i].r]; for (int j = 1; j <= p; j++) { res = sqrt(res); if (res == 1) break; } printf("%d\n", res); } else { T.update(q[i].l, q[i].r, 1, 1, 1, cnt); } } }