#include #include #include #include #include #include const int MAX_N = 50003; const int MAX_Q = 50003; const int WIDTH = 1000; const int LEN = 2 * MAX_N / WIDTH + 1; struct info { int lower, upper, color; info(){} info(const int _lower, const int _upper, const int _color) : lower(_lower), upper(_upper), color(_color){} }; info xborder[2 * MAX_N], yborder[2 * MAX_N]; unsigned long long h[MAX_N], memo[LEN][LEN]; unsigned short cnt[LEN][LEN][2 * WIDTH], kp[2 * WIDTH], trans[MAX_N]; std::vector color_table[LEN][LEN]; int X[2 * MAX_N], Y[2 * MAX_N], C[MAX_N]; bool used[MAX_N]; int N, Q; void transform_rectangle(){ std::vector > tmp(N); std::vector idX(2 * N, 0), idY(2 * N, 0); for(int i = 0; i < N; ++i){ int a, b, c, d, e; std::cin >> a >> b >> c >> d >> e; X[2 * i] = a, X[2 * i + 1] = c, Y[2 * i] = b, Y[2 * i + 1] = d; tmp[i] = {a, b, c, d, e}; } std::sort(X, X + 2 * N), std::sort(Y, Y + 2 * N); for(const std::vector& in : tmp){ const int a = std::lower_bound(X, X + 2 * N, in[0]) - X + idX[in[0]]++; const int b = std::lower_bound(Y, Y + 2 * N, in[1]) - Y + idY[in[1]]++; const int c = std::lower_bound(X, X + 2 * N, in[2]) - X + idX[in[2]]++; const int d = std::lower_bound(Y, Y + 2 * N, in[3]) - Y + idY[in[3]]++; const int e = in[4]; xborder[a] = {b, d, e}, xborder[c] = {b, d, -e}, yborder[b] = {a, c, e}, yborder[d] = {a, c, -e}; } } void pre_calc(){ unsigned long long cur_hash = 0; int curx = -1, cury = -1; const int length = (2 * N - 2) / WIDTH + 1; for(int i = 0; i < length; ++i){ memset(C, 0, sizeof(C)), cur_hash = 0, curx = i * WIDTH, cury = -1; for(int j = 0; j < length; ++j){ auto& ct = color_table[i][j]; const int stx = i * WIDTH + 1, sty = j * WIDTH + 1; for(int k = stx; k < std::min((i + 1) * WIDTH, 2 * N - 1); ++k){ const int c = xborder[k].color; if(c > 0){ if(!used[c]) ct.push_back(c), used[c] = true; }else{ if(!used[-c]) ct.push_back(-c), used[-c] = true; } } for(int k = sty; k < std::min((j + 1) * WIDTH, 2 * N - 1); ++k){ const int c = yborder[k].color; if(c > 0){ if(!used[c]) ct.push_back(c), used[c] = true; }else{ if(!used[-c]) ct.push_back(-c), used[-c] = true; } } while(cury < j * WIDTH){ ++cury; if(yborder[cury].lower <= curx && curx < yborder[cury].upper){ const int c = yborder[cury].color; if(c > 0){ if(++C[c] == 1) cur_hash ^= h[c]; }else{ if(--C[-c] == 0) cur_hash ^= h[-c]; } } } memo[i][j] = cur_hash; for(int k = 0; k < (int)color_table[i][j].size(); ++k){ const int c = color_table[i][j][k]; cnt[i][j][k] = C[c], used[c] = false; } } } } unsigned long long query(const int p, const int q){ const int x = std::upper_bound(X, X + 2 * N, p) - X - 1; const int y = std::upper_bound(Y, Y + 2 * N, q) - Y - 1; if(x < 0 || x >= 2 * N - 1 || y < 0 || y >= 2 * N - 1) return 0ULL; const int zx = x / WIDTH, zy = y / WIDTH; unsigned long long cur_hash = memo[zx][zy]; const auto& ct = color_table[zx][zy]; for(int i = 0; i < (int)ct.size(); ++i){ kp[trans[ct[i]] = i] = cnt[zx][zy][i]; } const int stx = zx * WIDTH + 1, sty = zy * WIDTH + 1; int curx = stx - 1, cury = sty - 1; while(curx < x){ ++curx; if(xborder[curx].lower <= cury && cury < xborder[curx].upper){ const int c = xborder[curx].color; if(c > 0){ if(++kp[trans[c]] == 1) cur_hash ^= h[c]; }else{ if(--kp[trans[-c]] == 0) cur_hash ^= h[-c]; } } } while(cury < y){ ++cury; if(yborder[cury].lower <= curx && curx < yborder[cury].upper){ const int c = yborder[cury].color; if(c > 0){ if(++kp[trans[c]] == 1) cur_hash ^= h[c]; }else{ if(--kp[trans[-c]] == 0) cur_hash ^= h[-c]; } } } return cur_hash; } int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); std::cin >> N; for(int i = 1; i <= N; ++i){ std::cin >> h[i]; } transform_rectangle(); std::cin >> Q; pre_calc(); for(int i = 0; i < 10; ++i){ int p, q; std::cin >> p >> q; std::cout << query(p, q) << "\n"; } return 0; }