結果
| 問題 |
No.2761 Substitute and Search
|
| コンテスト | |
| ユーザー |
sasa8uyauya
|
| 提出日時 | 2024-05-17 23:10:35 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,057 bytes |
| コンパイル時間 | 368 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 452,064 KB |
| 最終ジャッジ日時 | 2024-12-20 15:12:23 |
| 合計ジャッジ時間 | 51,858 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 2 WA * 2 TLE * 9 |
ソースコード
n,l,q=map(int,input().split())
def update(st,p,x,M):
p+=1
while p<=len(st):
st[p-1]+=x
st[p-1]%=M
p+=p&(-p)
return
def getsum(st,p,M):
p+=1
a=0
while p>0:
a+=st[p-1]
a%=M
p-=p&(-p)
return a
B1=1007
M1=1000000007
P1=[1]
for i in range(1,3001):
P1+=[P1[-1]*B1%M1]
R1=[1,pow(B1,M1-2,M1)]
for i in range(2,3001):
R1+=[R1[-1]*R1[1]%M1]
S=[]
s1=[]
for i in range(n):
s=input()
S+=[list(s)]
s1+=[[0]*l]
for j in range(l):
update(s1[i],j,ord(s[j])*P1[j]%M1,M1)
for _ in range(q):
query=input().split()
if int(query[0])==1:
_,k,c,d=query
k=int(k)-1
c=ord(c)
d=ord(d)
for i in range(n):
if ord(S[i][k])==c:
update(s1[i],k,(-c+d)*P1[k]%M1,M1)
S[i][k]=chr(d)
else:
_,t=query
h1=0
for i in range(len(t)):
h1+=ord(t[i])*P1[i]
h1%=M1
g=0
for i in range(n):
if len(t)<=10:
g+=t==S[i][:10]
else:
if t[:10]!=S[i][:len(t)]:
continue
if getsum(s1[i],len(t)-1,M1)==h1:
g+=1
print(g)
sasa8uyauya