結果
問題 | No.2554 MMA文字列2 (Query Version) |
ユーザー | Navier_Boltzmann |
提出日時 | 2024-03-09 18:00:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,686 ms / 5,000 ms |
コード長 | 2,671 bytes |
コンパイル時間 | 294 ms |
コンパイル使用メモリ | 81,968 KB |
実行使用メモリ | 280,132 KB |
最終ジャッジ日時 | 2024-09-29 21:18:54 |
合計ジャッジ時間 | 82,514 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
64,608 KB |
testcase_01 | AC | 50 ms
66,700 KB |
testcase_02 | AC | 95 ms
78,108 KB |
testcase_03 | AC | 113 ms
78,688 KB |
testcase_04 | AC | 116 ms
80,392 KB |
testcase_05 | AC | 94 ms
79,304 KB |
testcase_06 | AC | 107 ms
79,644 KB |
testcase_07 | AC | 99 ms
78,388 KB |
testcase_08 | AC | 75 ms
78,284 KB |
testcase_09 | AC | 96 ms
79,100 KB |
testcase_10 | AC | 106 ms
79,960 KB |
testcase_11 | AC | 89 ms
78,720 KB |
testcase_12 | AC | 166 ms
97,664 KB |
testcase_13 | AC | 2,011 ms
272,080 KB |
testcase_14 | AC | 577 ms
127,640 KB |
testcase_15 | AC | 1,504 ms
272,372 KB |
testcase_16 | AC | 1,329 ms
223,556 KB |
testcase_17 | AC | 1,794 ms
269,156 KB |
testcase_18 | AC | 842 ms
136,796 KB |
testcase_19 | AC | 1,033 ms
183,276 KB |
testcase_20 | AC | 1,818 ms
271,980 KB |
testcase_21 | AC | 1,037 ms
162,176 KB |
testcase_22 | AC | 2,121 ms
271,360 KB |
testcase_23 | AC | 2,170 ms
272,288 KB |
testcase_24 | AC | 2,101 ms
271,328 KB |
testcase_25 | AC | 2,125 ms
271,336 KB |
testcase_26 | AC | 2,152 ms
271,892 KB |
testcase_27 | AC | 2,156 ms
272,860 KB |
testcase_28 | AC | 2,074 ms
271,872 KB |
testcase_29 | AC | 2,131 ms
271,716 KB |
testcase_30 | AC | 2,103 ms
273,112 KB |
testcase_31 | AC | 2,153 ms
271,332 KB |
testcase_32 | AC | 406 ms
80,452 KB |
testcase_33 | AC | 415 ms
82,056 KB |
testcase_34 | AC | 456 ms
81,592 KB |
testcase_35 | AC | 465 ms
81,780 KB |
testcase_36 | AC | 459 ms
82,220 KB |
testcase_37 | AC | 1,812 ms
161,820 KB |
testcase_38 | AC | 1,763 ms
161,124 KB |
testcase_39 | AC | 1,706 ms
160,536 KB |
testcase_40 | AC | 1,768 ms
161,360 KB |
testcase_41 | AC | 1,770 ms
160,988 KB |
testcase_42 | AC | 1,833 ms
212,444 KB |
testcase_43 | AC | 1,853 ms
210,120 KB |
testcase_44 | AC | 1,906 ms
210,856 KB |
testcase_45 | AC | 1,801 ms
210,520 KB |
testcase_46 | AC | 1,770 ms
209,160 KB |
testcase_47 | AC | 2,686 ms
278,836 KB |
testcase_48 | AC | 2,493 ms
278,212 KB |
testcase_49 | AC | 2,501 ms
278,744 KB |
testcase_50 | AC | 2,464 ms
278,452 KB |
testcase_51 | AC | 2,494 ms
278,488 KB |
testcase_52 | AC | 2,515 ms
279,156 KB |
testcase_53 | AC | 2,532 ms
279,796 KB |
testcase_54 | AC | 2,511 ms
279,396 KB |
testcase_55 | AC | 2,502 ms
279,836 KB |
testcase_56 | AC | 2,503 ms
280,132 KB |
ソースコード
# import pypyjit# pypyjit.set_param("max_unroll_recursion=-1")from collections import *from functools import *from itertools import *from heapq import *import sys, math,random,time# input = sys.stdin.readlineclass SegTree:"""Segment Tree"""def __init__(self, init_val, segfunc, ide_ele):"""初期化init_val: 配列の初期値"""n = len(init_val)self.segfunc = segfuncself.ide_ele = ide_eleself.num = 1 << (n - 1).bit_length()self.tree = [ide_ele] * 2 * self.num# 配列の値を葉にセットfor i in range(n):self.tree[self.num + i] = init_val[i]# 構築していくfor i in range(self.num - 1, 0, -1):self.tree[i] = segfunc(self.tree[2 * i], self.tree[2 * i + 1])def update(self, k, x):"""k番目の値をxに更新k: index(0-index)x: update value"""k += self.numself.tree[k] = xwhile k > 1:tk = k>>1self.tree[tk] = self.segfunc(self.tree[tk<<1], self.tree[(tk<<1)+1])k >>= 1def query(self, l, r):"""[l, r)のsegfuncしたものを得るl: index(0-index)r: index(0-index)"""res_l = self.ide_eleres_r = self.ide_elel += self.numr += self.numwhile l < r:if l & 1:res_l = self.segfunc(res_l, self.tree[l])l += 1if r & 1:res_r = self.segfunc(self.tree[r - 1], res_r)l >>= 1r >>= 1res = self.segfunc(res_l,res_r)return resN = int(input())S = list(input())S = [ord(s)-ord('A') for s in S]Q = int(input())M = 26L = 2*M+1ide_ele = tuple([0]*(L))def segfunc(x,y):z = [x[i]+y[i] for i in range(L)]s = sum(y[:M])for i in range(M):z[i+M] = (z[i+M] + x[i]*(s-y[i]))for i in range(M):z[-1] = (z[-1]+x[i] * (x[i] - 1) // 2 * (s - y[i])+x[i] * y[i + M])return tuple(z)I = []for s in S:X = [0]*(L)X[s] = 1I.append(tuple(X))T = SegTree(I,segfunc,ide_ele)for _ in range(Q):query = tuple(input().split())if query[0]=='1':x,c = query[1:]x = int(x) - 1c = ord(c) - ord('A')X = [0]*(L)X[c] = 1T.update(x,tuple(X))else:l,r = map(int,query[1:])l -= 1print(T.query(l,r)[-1])# print(l,r,sum(T.query(l,r)[:M]),sum(T.query(l,r)[M:-1]))# print(T.query(8,N))