結果

問題 No.318 学学学学学
ユーザー takakintakakin
提出日時 2020-06-15 23:17:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,445 bytes
コンパイル時間 388 ms
コンパイル使用メモリ 87,148 KB
実行使用メモリ 134,776 KB
最終ジャッジ日時 2023-09-16 10:37:10
合計ジャッジ時間 13,971 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 175 ms
80,516 KB
testcase_01 AC 205 ms
86,304 KB
testcase_02 WA -
testcase_03 AC 200 ms
84,612 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 574 ms
108,016 KB
testcase_20 WA -
testcase_21 AC 88 ms
71,720 KB
testcase_22 AC 89 ms
71,608 KB
testcase_23 AC 89 ms
71,668 KB
testcase_24 AC 87 ms
71,392 KB
testcase_25 AC 88 ms
71,744 KB
testcase_26 AC 88 ms
71,460 KB
testcase_27 AC 88 ms
71,588 KB
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,heapq
input = sys.stdin.buffer.readline
n=int(input())
A=[int(i) for i in input().split()]

LV=(n-1).bit_length()
N0=2**LV
data=[0]*(2*N0)
lazy=[None]*(2*N0)

# 伝搬対象の区間を求める
def gindex(l, r):
  L=(l + N0)>>1; R = (r+N0) >> 1
  lc=0 if l & 1 else (L&-L).bit_length()
  rc=0 if r & 1 else (R&-R).bit_length()
  for i in range(LV):
    if rc<=i:
      yield R
    if L<R and lc<=i:
      yield L
    L>>=1; R>>=1

# 遅延伝搬処理
def propagates(*ids):
  for i in reversed(ids):
    v=lazy[i-1]
    if v is None:
      continue
    lazy[2*i-1]=lazy[2*i]=data[2*i-1]=data[2*i]=v>>1
    lazy[i-1]=None

# 区間[l, r)をxに更新
def update(l, r, x):
  *ids,=gindex(l, r)
  propagates(*ids)

  L=N0+l; R=N0+r
  v=x
  while L<R:
    if R&1:
      R-=1
      lazy[R-1]=data[R-1]=v
    if L & 1:
      lazy[L-1]=data[L-1]=v
      L+=1
    L>>=1; R>>=1; v<<=1
  for i in ids:
    data[i-1]=data[2*i-1]+data[2*i]

# 区間[l, r)内の合計を求める
def query(l, r):
  propagates(*gindex(l, r))
  L=N0+l; R=N0+r

  s=0
  while L<R:
    if R&1:
      R-=1
      s+=data[R-1]
    if L&1:
      s+=data[L-1]
      L+=1
    L>>=1; R>>=1
  return s

import collections
DL=collections.defaultdict(int)
DR=collections.defaultdict(int)
for i,a in enumerate(A):
  if DL[a]==0:
    DL[a]=i+1
  DR[a]=i+1

AA=sorted(list(set(A)))
for a in A:
  update(DL[a]-1,DR[a],a)
B=[]
for i in range(n):
  B.append(query(i,i+1))
print(*B)
0