結果

問題 No.1919 Many Monster Battles
ユーザー googol_S0googol_S0
提出日時 2022-04-29 23:02:47
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,869 bytes
コンパイル時間 258 ms
コンパイル使用メモリ 86,940 KB
実行使用メモリ 269,200 KB
最終ジャッジ日時 2023-09-11 14:28:59
合計ジャッジ時間 6,830 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
76,148 KB
testcase_01 AC 80 ms
71,564 KB
testcase_02 AC 79 ms
71,492 KB
testcase_03 AC 183 ms
80,556 KB
testcase_04 AC 181 ms
80,828 KB
testcase_05 AC 180 ms
80,784 KB
testcase_06 AC 179 ms
80,636 KB
testcase_07 AC 184 ms
80,568 KB
testcase_08 AC 184 ms
80,620 KB
testcase_09 AC 186 ms
80,908 KB
testcase_10 AC 183 ms
80,116 KB
testcase_11 AC 181 ms
81,072 KB
testcase_12 AC 184 ms
80,752 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from copy import *
def init(N,node,A,unit,func):
  while len(node):
    del node[-1]
  n=1
  while n<N:
    n<<=1
  for i in range(n*2-1):
    if len(node)<=i:
      node.append(unit)
    else:
      node[i]=unit
  for i in range(len(A)):
    node[n-1+i]=A[i]
  for i in range(n-2,-1,-1):
    node[i]=func(node[(i<<1)+1],node[(i<<1)+2])
  node.append(func)
  node.append(unit)
  node.append(n)

def upd(node,x,a):
  y=node[-1]+x
  node[y-1]+=a
  while y>1:
    y=y>>1
    node[y-1]=node[-3](node[(y<<1)-1],node[y<<1])

def query(node,l,r):
  x,y=l,r
  z=node[-1]-1
  rr=node[-2]
  rl=node[-2]
  while True:
    if x==y:
      return node[-3](rl,rr)
    if x&1:
      rl=node[-3](rl,node[x+z])
      x+=1
    if y&1:
      rr=node[-3](node[y+z-1],rr)
    if z==0:
      return node[-3](rl,rr)
    x>>=1
    y>>=1
    z>>=1

mod=10**9+7
def comp(x):
  y=sorted(set(x))
  d=dict()
  for i in range(len(y)):
    d[y[i]]=i
  return d

def solve(A,B):
  N=len(A)
  X=[(A[i],B[i]) for i in range(N)]
  X.sort()
  Y=[X[i][0]-X[i][1] for i in range(N)]
  Z=[X[i][0]+X[i][1] for i in range(N)]
  y,z=comp(Y),comp(Z)
  ANS=0
  segy=[]
  segz=[]
  init(N,segy,[],0,lambda x,y:x+y)
  init(N,segz,[],0,lambda x,y:x+y)
  c=0
  for i in range(N):
    if i and X[i]==X[i-1]:
      c+=1
    else:
      c=0
    a,b=y[Y[i]],z[Z[i]]
    ANS=(ANS+X[i][0]*(query(segy,0,a)+query(segz,0,b)-i+c))%mod
    upd(segy,a,1)
    upd(segz,b,1)
  segy=[]
  segz=[]
  init(N,segy,[],0,lambda x,y:x+y)
  init(N,segz,[],0,lambda x,y:x+y)
  c=0
  for i in range(N-1,-1,-1):
    if i+1<N and X[i]==X[i+1]:
      c+=1
    else:
      c=0
    a,b=y[Y[i]],z[Z[i]]
    ANS=(ANS-X[i][0]*(query(segy,a+1,N)+query(segz,b+1,N)-(N-1-i)+c))%mod
    upd(segy,a,1)
    upd(segz,b,1)
  return ANS

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
print(solve(A,B)*2%mod,solve(B,A)*2%mod)
0