結果
問題 | No.619 CardShuffle |
ユーザー | maspy |
提出日時 | 2020-04-09 02:53:01 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,976 bytes |
コンパイル時間 | 138 ms |
コンパイル使用メモリ | 81,812 KB |
実行使用メモリ | 122,352 KB |
最終ジャッジ日時 | 2024-07-19 07:23:49 |
合計ジャッジ時間 | 13,108 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
52,864 KB |
testcase_01 | AC | 38 ms
52,992 KB |
testcase_02 | AC | 38 ms
53,504 KB |
testcase_03 | AC | 38 ms
53,504 KB |
testcase_04 | AC | 36 ms
53,248 KB |
testcase_05 | AC | 34 ms
53,376 KB |
testcase_06 | AC | 35 ms
53,760 KB |
testcase_07 | AC | 38 ms
53,504 KB |
testcase_08 | AC | 37 ms
53,632 KB |
testcase_09 | AC | 36 ms
53,504 KB |
testcase_10 | AC | 36 ms
53,504 KB |
testcase_11 | AC | 36 ms
52,608 KB |
testcase_12 | AC | 34 ms
52,992 KB |
testcase_13 | AC | 35 ms
53,224 KB |
testcase_14 | AC | 35 ms
52,992 KB |
testcase_15 | AC | 36 ms
52,992 KB |
testcase_16 | WA | - |
testcase_17 | AC | 286 ms
93,344 KB |
testcase_18 | WA | - |
testcase_19 | AC | 336 ms
94,228 KB |
testcase_20 | AC | 481 ms
111,360 KB |
testcase_21 | WA | - |
testcase_22 | AC | 317 ms
97,444 KB |
testcase_23 | WA | - |
testcase_24 | AC | 323 ms
97,468 KB |
testcase_25 | AC | 525 ms
122,352 KB |
testcase_26 | AC | 613 ms
94,204 KB |
testcase_27 | AC | 265 ms
90,612 KB |
testcase_28 | WA | - |
testcase_29 | AC | 286 ms
90,612 KB |
testcase_30 | AC | 348 ms
94,336 KB |
testcase_31 | AC | 36 ms
52,608 KB |
testcase_32 | AC | 428 ms
111,584 KB |
testcase_33 | AC | 861 ms
113,536 KB |
testcase_34 | WA | - |
testcase_35 | AC | 434 ms
81,472 KB |
ソースコード
#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10 ** 9 + 7 class SegTree: """ segment tree with point modification and range product access. """ data_unit = None @classmethod def data_f(cls, A, B): if A is None: return B if B is None: return A n = len(A) m = len(B) if (n, m) == (1, 1): # A[0] * B[0] * return (A[0] * B[0] % MOD,) elif (n, m) == (1, 2): # A[0] * B[0] + B[1] + return (A[0] * B[0] % MOD, B[1]) elif (n, m) == (1, 3): # A[0] * B[0] + B[1] + B[2] * return (A[0] * B[0] % MOD, B[1], B[2]) elif (n, m) == (2, 1): # A[0] + A[1] + B[0] * return (A[0], A[1], B[0]) elif (n, m) == (2, 2): # A[0] + A[1] + B[0] + B[1] + return (A[0], A[1] + B[0] + B[1]) elif (n, m) == (2, 3): # A[0] + A[1] + B[0] + B[1] + B[2] * return (A[0], A[1] + B[0] + B[1], B[2]) elif (n, m) == (3, 1): # A[0] + A[1] + A[2] * B[0] * return (A[0], A[1], A[2] * B[0] % MOD) elif (n, m) == (3, 2): # A[0] + A[1] + A[2] * B[0] + B[1] + return (A[0], A[1] + A[2] * B[0] % MOD + B[1]) elif (n, m) == (3, 3): # A[0] + A[1] + A[2] * B[0] + B[1] + B[2] * return (A[0], A[1] + A[2] * B[0] % MOD + B[1], B[2]) def __init__(self, N): self.N = N self.data = [self.data_unit] * (N + N) def build(self, raw_data): data = self.data f = self.data_f N = self.N data[N:] = raw_data[:] for i in range(N - 1, 0, -1): data[i] = f(data[i << 1], data[i << 1 | 1]) def set_val(self, i, x): data = self.data f = self.data_f i += self.N data[i] = x while i > 1: i >>= 1 data[i] = f(data[i << 1], data[i << 1 | 1]) def fold(self, L, R): """ compute for [L, R) """ vL = vR = self.data_unit data = self.data f = self.data_f L += self.N R += self.N while L < R: if L & 1: vL = f(vL, data[L]) L += 1 if R & 1: R -= 1 vR = f(data[R], vR) L >>= 1 R >>= 1 return f(vL, vR) def cards_to_tpl(i): x, y = C[2 * i: 2 * i + 2] if y == b'+': return (int(x), 0) else: return (int(x),) N = int(readline()) N = (N + 1) // 2 seg = SegTree(N) C = readline().split() + [b'+'] seg.build([cards_to_tpl(i) for i in range(N)]) Q = int(readline()) for _ in range(Q): t, x, y = readline().split() x = int(x) - 1 y = int(y) - 1 if t == b'!': C[x], C[y] = C[y], C[x] for i in (x // 2, y // 2): seg.set_val(i, cards_to_tpl(i)) else: print(sum(seg.fold(x // 2, y // 2 + 1)))