#include #include #include #include #include #include const int MAX_N = 50000; struct info { int lower, upper, color; info() : info(2 * MAX_N + 1, -1, 0){} info(const int _lower, const int _upper, const int _color) : lower(_lower), upper(_upper), color(_color){} }; std::vector upx[2 * MAX_N], upy[2 * MAX_N]; int C[MAX_N]; int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); int N; std::cin >> N; std::vector h(N); for(int i = 0; i < N; ++i){ std::cin >> h[i]; } for(int i = 0; i < N; ++i){ int a, b, c, d, e; std::cin >> a >> b >> c >> d >> e; upx[a].emplace_back(b, d, e), upx[c].emplace_back(b, d, -e); upy[b].emplace_back(a, c, e), upy[d].emplace_back(a, c, -e); } int Q; std::cin >> Q; std::vector > z(Q); std::vector ord(Q); std::iota(ord.begin(), ord.end(), 0); for(int i = 0; i < Q; ++i){ int p, q; std::cin >> p >> q; z[i] = {p, q}; } const int width = 2 * ceil(sqrt(N)); std::sort(ord.begin(), ord.end(), [&](const int a, const int b){ const int u = z[a].first / width, v = z[b].first / width; return (u == v) ? (z[a].second < z[b].second) : (u < v); }); std::vector ans(Q); unsigned long long cur_hash = 0; int prv = -1, curx = -1, cury = -1; for(const int id : ord){ const int cur = z[id].first / width; if(prv != cur){ memset(C, 0, sizeof(C)), cur_hash = 0, prv = cur, curx = cur * width - 1, cury = -1; } // left while(curx > z[id].first){ for(const info& cur_info : upx[curx]){ if(cur_info.lower <= cury && cury < cur_info.upper){ const int c = cur_info.color; if(c > 0){ if(--C[c - 1] == 0) cur_hash ^= h[c - 1]; }else{ if(++C[-c - 1] == 1) cur_hash ^= h[-c - 1]; } } } --curx; } // right while(curx < z[id].first){ ++curx; for(const info& cur_info : upx[curx]){ if(cur_info.lower <= cury && cury < cur_info.upper){ const int c = cur_info.color; if(c > 0){ if(++C[c - 1] == 1) cur_hash ^= h[c - 1]; }else{ if(--C[-c - 1] == 0) cur_hash ^= h[-c - 1]; } } } } // up while(cury < z[id].second){ ++cury; for(const info& cur_info : upy[cury]){ if(cur_info.lower <= curx && curx < cur_info.upper){ const int c = cur_info.color; if(c > 0){ if(++C[c - 1] == 1) cur_hash ^= h[c - 1]; }else{ if(--C[-c - 1] == 0) cur_hash ^= h[-c - 1]; } } } } ans[id] = cur_hash; } for(int i = 0; i < Q; ++i){ std::cout << ans[i] << "\n"; } return 0; }