結果
問題 | No.961 Vibrant Fillumination |
ユーザー | kopricky |
提出日時 | 2019-12-09 04:28:55 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 851 ms / 5,000 ms |
コード長 | 4,897 bytes |
コンパイル時間 | 2,396 ms |
コンパイル使用メモリ | 79,636 KB |
実行使用メモリ | 119,788 KB |
最終ジャッジ日時 | 2023-10-19 00:17:46 |
合計ジャッジ時間 | 33,204 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
5,024 KB |
testcase_01 | AC | 3 ms
4,972 KB |
testcase_02 | AC | 364 ms
58,080 KB |
testcase_03 | AC | 398 ms
58,040 KB |
testcase_04 | AC | 381 ms
58,080 KB |
testcase_05 | AC | 402 ms
58,040 KB |
testcase_06 | AC | 366 ms
58,080 KB |
testcase_07 | AC | 388 ms
58,040 KB |
testcase_08 | AC | 374 ms
58,080 KB |
testcase_09 | AC | 388 ms
58,040 KB |
testcase_10 | AC | 837 ms
114,088 KB |
testcase_11 | AC | 851 ms
116,560 KB |
testcase_12 | AC | 812 ms
114,296 KB |
testcase_13 | AC | 815 ms
114,492 KB |
testcase_14 | AC | 822 ms
113,340 KB |
testcase_15 | AC | 794 ms
114,376 KB |
testcase_16 | AC | 817 ms
115,504 KB |
testcase_17 | AC | 779 ms
115,572 KB |
testcase_18 | AC | 815 ms
114,644 KB |
testcase_19 | AC | 810 ms
113,096 KB |
testcase_20 | AC | 810 ms
113,888 KB |
testcase_21 | AC | 790 ms
115,004 KB |
testcase_22 | AC | 794 ms
113,220 KB |
testcase_23 | AC | 789 ms
113,696 KB |
testcase_24 | AC | 800 ms
112,544 KB |
testcase_25 | AC | 833 ms
114,552 KB |
testcase_26 | AC | 217 ms
57,348 KB |
testcase_27 | AC | 411 ms
110,716 KB |
testcase_28 | AC | 222 ms
57,348 KB |
testcase_29 | AC | 486 ms
118,864 KB |
testcase_30 | AC | 614 ms
119,728 KB |
testcase_31 | AC | 455 ms
119,788 KB |
testcase_32 | AC | 455 ms
119,728 KB |
testcase_33 | AC | 3 ms
5,092 KB |
testcase_34 | AC | 584 ms
88,640 KB |
testcase_35 | AC | 466 ms
72,964 KB |
testcase_36 | AC | 451 ms
65,120 KB |
testcase_37 | AC | 443 ms
65,120 KB |
testcase_38 | AC | 417 ms
65,088 KB |
testcase_39 | AC | 430 ms
64,320 KB |
testcase_40 | AC | 410 ms
61,452 KB |
testcase_41 | AC | 436 ms
61,092 KB |
testcase_42 | AC | 415 ms
61,180 KB |
testcase_43 | AC | 422 ms
61,180 KB |
testcase_44 | AC | 438 ms
61,180 KB |
testcase_45 | AC | 425 ms
61,180 KB |
testcase_46 | AC | 443 ms
61,180 KB |
testcase_47 | AC | 413 ms
59,840 KB |
testcase_48 | AC | 433 ms
61,180 KB |
testcase_49 | AC | 436 ms
61,180 KB |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <cstring> #include <array> const int MAX_N = 50003; const int MAX_Q = 50003; const int WIDTH = 800; const int MAX_BLOCK = 2 * MAX_N / WIDTH + 1; struct event { int lower, upper, color; event(){} event(const int _lower, const int _upper, const int _color) : lower(_lower), upper(_upper), color(_color){} }; event xborder[2 * MAX_N], yborder[2 * MAX_N]; unsigned long long h[MAX_N], memo[MAX_BLOCK][MAX_BLOCK]; unsigned short cnt[MAX_BLOCK][MAX_BLOCK][2 * WIDTH], kp[2 * WIDTH], trans[MAX_N]; std::vector<unsigned short> color_table[MAX_BLOCK][MAX_BLOCK]; unsigned int smx[2 * MAX_N], smy[2 * MAX_N], C[MAX_N]; bool used[MAX_N]; int N, Q; void transform_rectangle(){ std::vector<std::array<int, 5> > tmp(N); std::vector<int> 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; ++smx[a + 1], ++smx[c + 1], ++smy[b + 1], ++smy[d + 1]; tmp[i] = {a, b, c, d, e}; } for(int i = 0; i < 2 * N; ++i){ smx[i + 1] += smx[i], smy[i + 1] += smy[i]; } for(const std::array<int, 5>& arr : tmp){ const int a = smx[arr[0]] + idX[arr[0]]++; const int b = smy[arr[1]] + idY[arr[1]]++; const int c = smx[arr[2]] + idX[arr[2]]++; const int d = smy[arr[3]] + idY[arr[3]]++; const int e = arr[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 = smx[p + 1] - 1; const int y = smy[q + 1] - 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 < Q; ++i){ int p, q; std::cin >> p >> q; std::cout << query(p, q) << "\n"; } return 0; }