結果

問題 No.2554 MMA文字列2 (Query Version)
ユーザー sepa38sepa38
提出日時 2023-11-23 16:05:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,911 ms / 5,000 ms
コード長 1,497 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 271,872 KB
最終ジャッジ日時 2023-11-23 16:07:04
合計ジャッジ時間 106,414 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
61,744 KB
testcase_01 AC 45 ms
61,744 KB
testcase_02 AC 105 ms
77,160 KB
testcase_03 AC 110 ms
76,940 KB
testcase_04 AC 144 ms
79,000 KB
testcase_05 AC 117 ms
78,104 KB
testcase_06 AC 113 ms
77,832 KB
testcase_07 AC 112 ms
76,648 KB
testcase_08 AC 84 ms
77,456 KB
testcase_09 AC 136 ms
78,872 KB
testcase_10 AC 123 ms
79,128 KB
testcase_11 AC 97 ms
76,424 KB
testcase_12 AC 394 ms
107,920 KB
testcase_13 AC 2,418 ms
268,740 KB
testcase_14 AC 723 ms
123,204 KB
testcase_15 AC 2,147 ms
263,048 KB
testcase_16 AC 1,464 ms
183,296 KB
testcase_17 AC 2,046 ms
236,896 KB
testcase_18 AC 896 ms
120,872 KB
testcase_19 AC 1,151 ms
157,840 KB
testcase_20 AC 2,377 ms
269,360 KB
testcase_21 AC 1,035 ms
138,020 KB
testcase_22 AC 2,711 ms
269,328 KB
testcase_23 AC 2,756 ms
268,856 KB
testcase_24 AC 2,738 ms
269,240 KB
testcase_25 AC 2,748 ms
268,756 KB
testcase_26 AC 2,754 ms
268,728 KB
testcase_27 AC 2,784 ms
268,984 KB
testcase_28 AC 2,743 ms
269,496 KB
testcase_29 AC 2,753 ms
269,112 KB
testcase_30 AC 2,761 ms
268,784 KB
testcase_31 AC 2,659 ms
269,112 KB
testcase_32 AC 462 ms
79,144 KB
testcase_33 AC 468 ms
79,636 KB
testcase_34 AC 482 ms
79,288 KB
testcase_35 AC 502 ms
80,456 KB
testcase_36 AC 510 ms
80,812 KB
testcase_37 AC 2,577 ms
201,272 KB
testcase_38 AC 2,490 ms
200,316 KB
testcase_39 AC 2,487 ms
200,720 KB
testcase_40 AC 2,562 ms
202,516 KB
testcase_41 AC 2,521 ms
202,704 KB
testcase_42 AC 2,602 ms
227,972 KB
testcase_43 AC 2,596 ms
227,052 KB
testcase_44 AC 2,587 ms
227,896 KB
testcase_45 AC 2,610 ms
227,512 KB
testcase_46 AC 2,640 ms
227,768 KB
testcase_47 AC 2,886 ms
270,764 KB
testcase_48 AC 2,903 ms
270,792 KB
testcase_49 AC 2,889 ms
270,148 KB
testcase_50 AC 2,747 ms
270,392 KB
testcase_51 AC 2,758 ms
270,264 KB
testcase_52 AC 2,818 ms
271,784 KB
testcase_53 AC 2,843 ms
271,852 KB
testcase_54 AC 2,859 ms
270,560 KB
testcase_55 AC 2,911 ms
271,872 KB
testcase_56 AC 2,845 ms
271,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class segt:
  def __init__(self, n, calc):
    self.num = 2 ** (n - 1).bit_length()
    self.data = [[0]*53 for _ in range(2*self.num)]
    self.calc = calc

  def update(self, idx, x):
    idx += self.num - 1
    self.data[idx] = [0] * 53
    self.data[idx][x] = 1
    while idx > 0:
      idx = (idx - 1) >> 1
      self.data[idx] = self.calc(self.data[2*idx+1][:], self.data[2*idx+2][:])[:]

  def renew(self, idx, x):
    self.update(idx, self.calc(self.get(idx), x))

  def prod(self, left, right):
    l = left + self.num
    r = right + self.num
    res_l = [0] * 53
    res_r = [0] * 53
    while l < r:
      if l % 2:
        res_l = self.calc(res_l[:], self.data[l-1][:])[:]
        l += 1
      if r % 2:
        r -= 1
        res_r = self.calc(self.data[r-1][:], res_r[:])[:]
      l >>= 1
      r >>= 1
    return self.calc(res_l, res_r)

  def get(self, idx):
    return self.data[idx+self.num-1]

def func(x, y):
  res = [x[i] + y[i] for i in range(53)]
  s = sum(y[:26])
  for i in range(26):
    res[i+26] += x[i] * (s - y[i])
  for i in range(26):
    res[52] += x[i] * (x[i] - 1) // 2 * (s - y[i])
    res[52] += x[i] * y[i+26]

  return res


n = int(input())
s = list(map(lambda x: ord(x)-65, input()))
st = segt(n, func)
for i in range(n):
  st.update(i, s[i])
for _ in range(int(input())):
  t, x, y = map(str, input().split())
  if t == "1":
    x = int(x) - 1
    y = ord(y) - 65
    st.update(x, y)
  else:
    l = int(x) - 1
    r = int(y)
    print(st.prod(l, r)[52])
0