結果

問題 No.318 学学学学学
ユーザー takakintakakin
提出日時 2020-06-15 23:17:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,445 bytes
コンパイル時間 72 ms
コンパイル使用メモリ 10,908 KB
実行使用メモリ 43,920 KB
最終ジャッジ日時 2023-09-16 10:36:52
合計ジャッジ時間 6,893 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
16,328 KB
testcase_01 AC 255 ms
14,624 KB
testcase_02 WA -
testcase_03 AC 199 ms
13,776 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

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