結果
問題 |
No.961 Vibrant Fillumination
|
ユーザー |
![]() |
提出日時 | 2025-04-16 16:34:47 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,333 bytes |
コンパイル時間 | 333 ms |
コンパイル使用メモリ | 81,772 KB |
実行使用メモリ | 148,216 KB |
最終ジャッジ日時 | 2025-04-16 16:37:49 |
合計ジャッジ時間 | 8,422 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 1 |
other | TLE * 1 -- * 47 |
ソースコード
import sys def main(): input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr += 1 h = list(map(int, input[ptr:ptr+N])) ptr += N events = [] for _ in range(N): a = int(input[ptr]) b = int(input[ptr+1]) c = int(input[ptr+2]) d = int(input[ptr+3]) e = int(input[ptr+4]) ptr += 5 start_x = a end_x = c # Remove event at x = c_i (since the interval is [a_i, c_i-1]) y_low = b y_high = d - 1 # The y interval is [b_i, d_i-1] events.append((start_x, 'add', y_low, y_high, e)) events.append((end_x, 'remove', y_low, y_high, e)) Q = int(input[ptr]) ptr += 1 queries = [] for i in range(Q): p = int(input[ptr]) q = int(input[ptr+1]) ptr += 2 queries.append((p, q, i)) # Combine events and queries into a single list for processing sorted_items = [] for event in events: x = event[0] type_code = 0 if event[1] == 'remove' else 1 sorted_items.append((x, type_code, event)) for p, q, idx in queries: sorted_items.append((p, 2, ('query', p, q, idx))) # Sort by x, then by type_code (remove (0) comes before add (1), then queries (2)) sorted_items.sort(key=lambda x: (x[0], x[1])) active_intervals = [] ans = [0] * Q for item in sorted_items: x, type_code, payload = item if type_code in (0, 1): # Process event event_type = payload[1] y_low = payload[2] y_high = payload[3] e = payload[4] if event_type == 'add': active_intervals.append((y_low, y_high, e)) else: # Remove the interval; since there might be duplicates, we remove the first occurrence try: active_intervals.remove((y_low, y_high, e)) except ValueError: pass else: # Process query _, p, q, idx = payload current_xor = 0 for (yl, yh, e_val) in active_intervals: if yl <= q <= yh: current_xor ^= h[e_val - 1] ans[idx] = current_xor for a in ans: print(a) if __name__ == "__main__": main()