結果
問題 | No.2935 Division Into 3 (Mex Edition) |
ユーザー | amesyu |
提出日時 | 2024-10-12 01:19:15 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,956 bytes |
コンパイル時間 | 1,413 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 292,792 KB |
最終ジャッジ日時 | 2024-10-12 01:20:22 |
合計ジャッジ時間 | 62,489 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 482 ms
245,164 KB |
testcase_01 | AC | 456 ms
245,352 KB |
testcase_02 | AC | 482 ms
255,592 KB |
testcase_03 | AC | 2,270 ms
277,836 KB |
testcase_04 | AC | 2,901 ms
289,256 KB |
testcase_05 | AC | 3,059 ms
290,416 KB |
testcase_06 | AC | 3,057 ms
290,552 KB |
testcase_07 | AC | 2,632 ms
285,852 KB |
testcase_08 | AC | 2,640 ms
288,412 KB |
testcase_09 | AC | 2,820 ms
292,792 KB |
testcase_10 | AC | 2,861 ms
292,760 KB |
testcase_11 | AC | 2,033 ms
290,420 KB |
testcase_12 | AC | 2,481 ms
277,248 KB |
testcase_13 | AC | 2,967 ms
274,800 KB |
testcase_14 | AC | 2,944 ms
289,676 KB |
testcase_15 | AC | 2,734 ms
278,268 KB |
testcase_16 | AC | 2,205 ms
274,016 KB |
testcase_17 | AC | 3,033 ms
290,608 KB |
testcase_18 | AC | 2,994 ms
289,660 KB |
testcase_19 | AC | 2,610 ms
273,716 KB |
testcase_20 | AC | 2,856 ms
277,088 KB |
testcase_21 | AC | 2,180 ms
275,528 KB |
testcase_22 | WA | - |
testcase_23 | AC | 2,891 ms
276,504 KB |
ソースコード
from bisect import bisect_left, bisect_right LOG = 17 MAX_N = 2**LOG # 16 INF = 10**9 N = int(input()) A = [*map(int, input().split())] ap = [[] for _ in range(MAX_N)] for i in range(N): ap[A[i]].append(i) treeL = [[[] for _ in range(2*MAX_N)] for __ in range(3)] treeR = [[[] for _ in range(2*MAX_N)] for __ in range(3)] interval = [(-1, -1)] * 2 * MAX_N for t in range(1, 2*MAX_N): if t == 1: l, r = 0, MAX_N else: pl, pr = interval[t//2] if t&1: l, r = (pl + pr) >> 1, pr else: l, r = pl, (pl + pr) >> 1 idx = [] for x in range(l, r): for i in ap[x]: idx.append(i) idx.sort() for c in range(1, 4): cnt = [0] * (r - l) R, now = 0, 0 for i in range(len(idx)): assert i <= R while R < len(idx) and now < r - l: pos = A[idx[R]] - l cnt[pos] += 1 if cnt[pos] == c: now += 1 R += 1 if now == r - l: treeL[c-1][t].append(idx[i]) treeR[c-1][t].append(idx[R-1]) if cnt[A[idx[i]]-l] == c: now -= 1 cnt[A[idx[i]]-l] -= 1 treeL[c-1][t].append(INF) treeR[c-1][t].append(INF) interval[t] = (l, r) def query(l, r): mex = [] for c in range(1, 4): ptr = 2 while ptr < 2*MAX_N: L, R = interval[ptr] p = bisect_left(treeL[c-1][ptr], l) p = treeR[c-1][ptr][p] if p < r: ptr = (ptr^1)*2 else: ptr <<= 1 mex.append(ptr//2 - MAX_N) return mex Q = int(input()) ansi = 0 for _ in range(Q): alpha, beta = map(int, input().split()) l, r = alpha ^ ansi, beta ^ ansi mex1, mex2, mex3 = query(l-1, r) ansi = mex1+mex2+mex3 if mex3 == 0: ansi = min(ansi, r-l-1) if mex2 == 0: ansi = min(ansi, r-l) print(ansi)