結果
問題 | No.961 Vibrant Fillumination |
ユーザー | Pachicobue |
提出日時 | 2019-12-09 02:59:52 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,399 ms / 5,000 ms |
コード長 | 4,002 bytes |
コンパイル時間 | 2,916 ms |
コンパイル使用メモリ | 228,384 KB |
実行使用メモリ | 36,176 KB |
最終ジャッジ日時 | 2024-06-11 04:43:38 |
合計ジャッジ時間 | 62,388 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
5,632 KB |
testcase_01 | AC | 3 ms
5,632 KB |
testcase_02 | AC | 1,185 ms
36,044 KB |
testcase_03 | AC | 1,215 ms
36,172 KB |
testcase_04 | AC | 1,235 ms
36,172 KB |
testcase_05 | AC | 1,223 ms
36,172 KB |
testcase_06 | AC | 1,156 ms
36,044 KB |
testcase_07 | AC | 1,170 ms
36,048 KB |
testcase_08 | AC | 1,189 ms
36,172 KB |
testcase_09 | AC | 1,267 ms
36,172 KB |
testcase_10 | AC | 1,337 ms
35,920 KB |
testcase_11 | AC | 1,325 ms
36,040 KB |
testcase_12 | AC | 1,337 ms
36,040 KB |
testcase_13 | AC | 1,319 ms
36,044 KB |
testcase_14 | AC | 1,311 ms
36,044 KB |
testcase_15 | AC | 1,314 ms
36,172 KB |
testcase_16 | AC | 1,293 ms
36,172 KB |
testcase_17 | AC | 1,303 ms
36,044 KB |
testcase_18 | AC | 1,336 ms
36,172 KB |
testcase_19 | AC | 1,344 ms
36,176 KB |
testcase_20 | AC | 1,399 ms
36,048 KB |
testcase_21 | AC | 1,299 ms
36,048 KB |
testcase_22 | AC | 1,335 ms
36,044 KB |
testcase_23 | AC | 1,314 ms
36,048 KB |
testcase_24 | AC | 1,321 ms
36,176 KB |
testcase_25 | AC | 1,336 ms
36,172 KB |
testcase_26 | AC | 1,078 ms
36,044 KB |
testcase_27 | AC | 732 ms
36,172 KB |
testcase_28 | AC | 1,065 ms
36,176 KB |
testcase_29 | AC | 692 ms
36,044 KB |
testcase_30 | AC | 520 ms
36,044 KB |
testcase_31 | AC | 313 ms
36,040 KB |
testcase_32 | AC | 412 ms
35,916 KB |
testcase_33 | AC | 4 ms
5,632 KB |
testcase_34 | AC | 1,187 ms
36,176 KB |
testcase_35 | AC | 1,159 ms
35,916 KB |
testcase_36 | AC | 1,186 ms
36,044 KB |
testcase_37 | AC | 1,247 ms
36,044 KB |
testcase_38 | AC | 1,214 ms
36,048 KB |
testcase_39 | AC | 1,248 ms
35,912 KB |
testcase_40 | AC | 1,227 ms
36,176 KB |
testcase_41 | AC | 1,270 ms
36,172 KB |
testcase_42 | AC | 1,242 ms
36,044 KB |
testcase_43 | AC | 1,222 ms
36,172 KB |
testcase_44 | AC | 1,227 ms
36,044 KB |
testcase_45 | AC | 1,257 ms
36,176 KB |
testcase_46 | AC | 1,262 ms
36,044 KB |
testcase_47 | AC | 1,309 ms
36,048 KB |
testcase_48 | AC | 1,243 ms
36,172 KB |
testcase_49 | AC | 1,251 ms
36,044 KB |
ソースコード
#include <bits/stdc++.h> using ull = unsigned long long; using usize = std::size_t; int main() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false); usize N; std::cin >> N; std::vector<ull> h(N + 1, 0ULL); // ハッシュ値 for (usize i = 1; i <= N; i++) { std::cin >> h[i]; } constexpr ull X = 300000; // eps用(i/Xを足してdistinctにする) std::vector<ull> eps(X + 1, 0); // eps用(i/Xを足してdistinctにする) std::vector<ull> A(N + 1, 0), B(N + 1, 0), C(N + 1, 0), D(N + 1, 0); // フィルム座標(座圧前) std::vector<ull> E(N + 1, 0); // 色 std::vector<ull> unzip; std::map<ull, usize> zip; for (usize i = 1; i <= N; i++) { std::cin >> A[i] >> B[i] >> C[i] >> D[i] >> E[i]; A[i]++, B[i]++, C[i]++, D[i]++; A[i] = A[i] * X + (eps[A[i]]++); B[i] = B[i] * X + (eps[B[i]]++); C[i] = C[i] * X + (eps[C[i]]++); D[i] = D[i] * X + (eps[D[i]]++); unzip.push_back(A[i]), unzip.push_back(B[i]), unzip.push_back(C[i]), unzip.push_back(D[i]); } usize QN; std::cin >> QN; std::vector<usize> P(QN), Q(QN); // クエリ座標(座圧前) for (usize i = 0; i < QN; i++) { std::cin >> P[i] >> Q[i]; P[i]++, Q[i]++; P[i] = P[i] * X + (eps[P[i]]++); Q[i] = Q[i] * X + (eps[Q[i]]++); unzip.push_back(P[i]), unzip.push_back(Q[i]); } std::sort(unzip.begin(), unzip.end()); unzip.erase(std::unique(unzip.begin(), unzip.end()), unzip.end()); const usize L = unzip.size(); for (usize i = 0; i < L; i++) { zip[unzip[i]] = i; } std::vector<usize> a(N + 1, 0), b(N + 1, 0), c(N + 1, L), d(N + 1, L), e(N + 1, 0); std::vector<int> lr(L + 1, 0), du(L + 1, 0); // 左右矢印,上下矢印 for (usize i = 1; i <= N; i++) { a[i] = zip[A[i]], b[i] = zip[B[i]], c[i] = zip[C[i]], d[i] = zip[D[i]]; e[i] = E[i]; lr[a[i]] = du[b[i]] = int(i), lr[c[i]] = du[d[i]] = -int(i); } std::vector<usize> p(QN), q(QN); for (usize i = 0; i < QN; i++) { p[i] = zip[P[i]], q[i] = zip[Q[i]]; } constexpr usize BS = 800; std::vector<usize> inds(QN); std::iota(inds.begin(), inds.end(), 0UL); std::sort(inds.begin(), inds.end(), [&](const usize i, const usize j) { const usize bi = p[i] / BS, bj = p[j] / BS; return bi != bj ? bi < bj : q[i] != q[j] ? (q[i] < q[j])^(bi%2) : p[i] < p[j]; }); std::vector<usize> color_cnt(N + 1, 0); ull hash = 0; auto add_film = [&](const usize i) { // フィルムiを追加 const usize c = e[i]; if (color_cnt[c]++ == 0) { hash ^= h[c]; } }; auto del_film = [&](const usize i) { // フィルムiを削除 const usize c = e[i]; if (--color_cnt[c] == 0) { hash ^= h[c]; } }; auto add_del_film = [&](const int i) { if (i > 0) { add_film(usize(i)); } if (i < 0) { del_film(usize(-i)); } }; std::vector<ull> answer(QN); usize x = 0, y = 0; auto von = [&](const usize x, const usize y) { return b[(usize)std::abs(lr[x])] <= y and y < d[(usize)std::abs(lr[x])]; }; auto hon = [&](const usize x, const usize y) { return a[(usize)std::abs(du[y])] <= x and x < c[(usize)std::abs(du[y])]; }; for (const usize i : inds) { const usize nx = p[i], ny = q[i]; // 次のクエリ点 for (; x < nx; x++) { if (von(x + 1, y)) { add_del_film(lr[x + 1]); } } for (; x > nx; x--) { if (von(x, y)) { add_del_film(-lr[x]); } } for (; y < ny; y++) { if (hon(x, y + 1)) { add_del_film(du[y + 1]); } } for (; y > ny; y--) { if (hon(x, y)) { add_del_film(-du[y]); } } answer[i] = hash; } for (usize i = 0; i < QN; i++) { std::cout << answer[i] << "\n"; } return 0; }