結果

問題 No.2761 Substitute and Search
ユーザー sasa8uyauyasasa8uyauya
提出日時 2024-05-17 22:59:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,284 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 82,488 KB
実行使用メモリ 134,620 KB
最終ジャッジ日時 2024-05-17 22:59:59
合計ジャッジ時間 9,448 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
63,088 KB
testcase_01 AC 47 ms
62,712 KB
testcase_02 AC 48 ms
63,560 KB
testcase_03 AC 47 ms
62,816 KB
testcase_04 WA -
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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
B2=1009
M2=1000000009

P1=[1]
P2=[1]
for i in range(1,3001):
  P1+=[P1[-1]*B1%M1]
  P2+=[P2[-1]*B2%M2]
R1=[1,pow(B1,M1-2,M1)]
R2=[1,pow(B2,M2-2,M2)]
for i in range(2,3001):
  R1+=[R1[-1]*R1[1]%M1]
  R2+=[R1[-1]*R2[1]%M2]

s1=[]
s2=[]
for i in range(n):
  s=input()
  s1+=[[0]*l]
  s2+=[[0]*l]
  for j in range(l):
    update(s1[i],j,ord(s[j])*P1[j]%M1,M1)
    update(s2[i],j,ord(s[j])*P2[j]%M2,M2)

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 (getsum(s1[i],k,M1)-getsum(s1[i],k-1,M1))*R1[k]%M1==c and (getsum(s2[i],k,M2)-getsum(s2[i],k-1,M2))*R2[k]%M2==c:
        update(s1[i],k,(-c+d)*P1[k]%M1,M1)
        update(s2[i],k,(-c+d)*P2[k]%M2,M2)
  else:
    _,t=query
    h1=0
    h2=0
    for i in range(len(t)):
      h1+=ord(t[i])*P1[i]
      h1%=M1
      h2+=ord(t[i])*P2[i]
      h2%=M2
    g=0
    for i in range(n):
      if getsum(s1[i],len(t)-1,M1)==h1 and getsum(s2[i],len(t)-1,M2)==h2:
        g+=1
    print(g)
0