結果
問題 | No.2498 OX Operations |
ユーザー | KumaTachiRen |
提出日時 | 2023-09-04 13:18:21 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,506 ms / 4,000 ms |
コード長 | 3,361 bytes |
コンパイル時間 | 404 ms |
コンパイル使用メモリ | 81,924 KB |
実行使用メモリ | 101,904 KB |
最終ジャッジ日時 | 2024-06-22 11:49:07 |
合計ジャッジ時間 | 15,179 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
53,932 KB |
testcase_01 | AC | 40 ms
54,000 KB |
testcase_02 | AC | 40 ms
53,564 KB |
testcase_03 | AC | 54 ms
64,100 KB |
testcase_04 | AC | 42 ms
53,540 KB |
testcase_05 | AC | 41 ms
53,856 KB |
testcase_06 | AC | 40 ms
54,536 KB |
testcase_07 | AC | 53 ms
62,652 KB |
testcase_08 | AC | 53 ms
63,892 KB |
testcase_09 | AC | 51 ms
64,280 KB |
testcase_10 | AC | 54 ms
64,288 KB |
testcase_11 | AC | 101 ms
76,632 KB |
testcase_12 | AC | 126 ms
77,036 KB |
testcase_13 | AC | 124 ms
76,980 KB |
testcase_14 | AC | 133 ms
77,168 KB |
testcase_15 | AC | 843 ms
90,744 KB |
testcase_16 | AC | 1,506 ms
99,992 KB |
testcase_17 | AC | 668 ms
88,896 KB |
testcase_18 | AC | 977 ms
94,280 KB |
testcase_19 | AC | 849 ms
93,272 KB |
testcase_20 | AC | 1,039 ms
95,928 KB |
testcase_21 | AC | 1,154 ms
100,572 KB |
testcase_22 | AC | 643 ms
89,716 KB |
testcase_23 | AC | 567 ms
87,908 KB |
testcase_24 | AC | 1,203 ms
101,096 KB |
testcase_25 | AC | 1,285 ms
101,904 KB |
testcase_26 | AC | 1,190 ms
100,732 KB |
ソースコード
import sys def popcount(n): c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555) c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333) c = (c & 0x0F0F0F0F0F0F0F0F) + ((c >> 4) & 0x0F0F0F0F0F0F0F0F) c = (c & 0x00FF00FF00FF00FF) + ((c >> 8) & 0x00FF00FF00FF00FF) c = (c & 0x0000FFFF0000FFFF) + ((c >> 16) & 0x0000FFFF0000FFFF) c = (c & 0x00000000FFFFFFFF) + ((c >> 32) & 0x00000000FFFFFFFF) return c class DualSegTree: def __init__(self, n, comp, id): self.n = n self.comp = comp self.id = id self.sz = 1 self.log = 0 while self.sz < n: self.sz <<= 1 self.log += 1 self.lz = [id] * (self.sz * 2) def push(self, p): self.lz[p << 1] = self.comp(self.lz[p], self.lz[p << 1]) self.lz[(p << 1) + 1] = self.comp(self.lz[p], self.lz[(p << 1) + 1]) self.lz[p] = self.id def push_all(self, p): for i in range(self.log, 0, -1): self.push(p >> i) def get(self, p): P = p + self.sz self.push_all(P) return self.lz[P] def set(self, p, f): P = p + self.sz self.push_all(P) self.lz[P] = f def apply(self, l, r, f): if l >= r: return L = l + self.sz R = r + self.sz for i in range(self.log, 0, -1): if ((L >> i) << i) != L: self.push(L >> i) if ((R >> i) << i) != R: self.push((R - 1) >> i) while L < R: if L & 1: self.lz[L] = self.comp(f, self.lz[L]) L += 1 if R & 1: R -= 1 self.lz[R] = self.comp(f, self.lz[R]) L >>= 1 R >>= 1 LOG = 30 MASK = (1 << LOG) - 1 MOD = 998244353 def comp(f, g): return ((~g[0] & f[0]) | (g[0] & f[1]), (~g[1] & f[0]) | (g[1] & f[1])) id = (0, MASK) s = input().split(" ") n = int(s[0]) q = int(s[1]) m = list(map(int, input().split())) seg = DualSegTree(n, comp, id) for i in range(q): s = input().split(" ") l = int(s[1]) - 1 r = int(s[2]) x = int(s[3]) seg.apply(l, r, (x, MASK if s[0] == "o" else MASK ^ x)) fact = [1] * 100 ifact = [1] * 100 for i in range(1, 100): fact[i] = fact[i - 1] * i % MOD ifact[99] = pow(fact[99], MOD - 2, MOD) for i in range(99, 0, -1): ifact[i - 1] = ifact[i] * i % MOD def binom(n, k): return 0 if k < 0 or k > n else fact[n] * ifact[k] % MOD * ifact[n - k] % MOD prod = [1] * (LOG + 1) for p in range(n): r = seg.get(p) b = r[0] c = r[1] ma = m[p] + 1 f = [0] * (LOG + 1) cnt = [0, 0, 0] a = popcount(((ma ^ MASK) & b) | (ma & c)) for i in range(LOG): a -= (((ma ^ MASK) & b) | (ma & c)) & 1 a += b & 1 if ma & 1: for j in range(LOG + 1): f[j] += binom(cnt[1], j - a - cnt[2]) * (1 << (cnt[0] + cnt[2])) % MOD a -= b & 1 cnt[(b & 1) + (c & 1)] += 1 ma >>= 1 b >>= 1 c >>= 1 for i in range(LOG): f[i + 1] += f[i] if f[i + 1] >= MOD: f[i + 1] -= MOD for i in range(LOG + 1): prod[i] = prod[i] * f[i] % MOD ans = LOG * prod[LOG] % MOD for i in range(LOG): ans -= prod[i] if ans < 0: ans += MOD print(ans)